You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2017/11/28 18:15:04 UTC
[myfaces-tobago] 01/02: TOBAGO-1831 'selected' markup should change
on client sided tabgroup * 'selected' markup now changes on tab switch *
Utils method for data-tobago-markup added * a disabled AND active tab will
now rendered as disabled instead of active * fix style for IE11
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit 3b5f966e98198a43405e52a2911f93c4cc9706f8
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Tue Nov 28 19:00:07 2017 +0100
TOBAGO-1831 'selected' markup should change on client sided tabgroup
* 'selected' markup now changes on tab switch
* Utils method for data-tobago-markup added
* a disabled AND active tab will now rendered as disabled instead of active
* fix style for IE11
---
.../renderkit/renderer/TabGroupRenderer.java | 11 ++-
tobago-core/src/main/resources/scss/_tobago.scss | 1 +
.../tobago-bootstrap/_version/js/tobago-tab.js | 92 +++++++---------------
.../tobago-bootstrap/_version/js/tobago-utils.js | 49 +++++++++---
4 files changed, 75 insertions(+), 78 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TabGroupRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TabGroupRenderer.java
index 44ad311..253d08f 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TabGroupRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TabGroupRenderer.java
@@ -226,8 +226,11 @@ public class TabGroupRenderer extends RendererBase implements ComponentSystemEve
final LabelWithAccessKey label = new LabelWithAccessKey(tab);
final boolean disabled = tab.isDisabled();
final String tabId = tab.getClientId(facesContext);
+ Markup markup = tab.getMarkup() != null ? tab.getMarkup() : Markup.NULL;
- Markup markup = activeIndex == index ? Markup.SELECTED : Markup.NULL;
+ if (activeIndex == index) {
+ markup = markup.add(Markup.SELECTED);
+ }
final FacesMessage.Severity maxSeverity
= ComponentUtils.getMaximumSeverityOfChildrenMessages(facesContext, tab);
if (maxSeverity != null) {
@@ -259,10 +262,10 @@ public class TabGroupRenderer extends RendererBase implements ComponentSystemEve
if (!tab.isDisabled()) {
writer.writeAttribute(DataAttributes.TOGGLE, "tab", false);
}
- if (activeIndex == index) {
- writer.writeClassAttribute(BootstrapClass.NAV_LINK, BootstrapClass.ACTIVE);
- } else if (tab.isDisabled()) {
+ if (tab.isDisabled()) {
writer.writeClassAttribute(BootstrapClass.NAV_LINK, BootstrapClass.DISABLED);
+ } else if (activeIndex == index) {
+ writer.writeClassAttribute(BootstrapClass.NAV_LINK, BootstrapClass.ACTIVE);
} else {
writer.writeClassAttribute(BootstrapClass.NAV_LINK);
}
diff --git a/tobago-core/src/main/resources/scss/_tobago.scss b/tobago-core/src/main/resources/scss/_tobago.scss
index 3458180..f763bde 100644
--- a/tobago-core/src/main/resources/scss/_tobago.scss
+++ b/tobago-core/src/main/resources/scss/_tobago.scss
@@ -1158,6 +1158,7 @@ th.tobago-sheet-headerCell-markup-filler > .tobago-sheet-header {
justify-content: space-between;
align-content: center;
margin-left: 0.2rem;
+ z-index: 0; /* IE11 fix to hide bottom border on active tab */
.nav-link:not([href]):not([tabindex]) {
/* fix .nav-links without 'href'; bootstrap tab only works if 'href' is set */
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-tab.js b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-tab.js
index d647ab5..b953891 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-tab.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-tab.js
@@ -21,75 +21,39 @@ Tobago.TabGroup = {};
* Initializes the tab-groups.
* @param elements a jQuery object to initialize (ajax) or null for initializing the whole document (full load).
*/
-Tobago.TabGroup.init = function(elements) {
+Tobago.TabGroup.init = function (elements) {
- var tabGroups = Tobago.Utils.selectWithJQuery(elements, ".tobago-tabGroup");
+ var $tabGroups = Tobago.Utils.selectWithJQuery(elements, ".tobago-tabGroup");
+ var markupString = "selected";
+ var markupCssClass = "tobago-tab-markup-selected";
// setting the active index
- tabGroups.each(function () {
- jQuery(this).find(".tobago-tabGroup-header").first()
- .children(".tobago-tab").find(".nav-link:not(.disabled)")
- .parent()
- .click(function () {
- // Update the hidden field for the active index.
- var tab = jQuery(this);
- var tabGroup = tab.parents(".tobago-tabGroup:first");
- var hidden = tabGroup.children("input");
- var activeIndex = tab.attr("tabgroupindex");
- hidden.val(activeIndex);
- })
- });
-
- // initialize previous button
- tabGroups.find("[data-tobago-tabgroup-toolbar-prev]").click(function() {
- var tabGroup = jQuery(this).parents(".tobago-tabGroup:first");
- var selected = tabGroup.find(".tobago-tab-markup-selected");
- // the nearest of the previous siblings, which are not disabled
- selected.prevAll(".nav-link:not(.disabled):first").click();
- });
-
- // initialize next button
- tabGroups.find("[data-tobago-tabgroup-toolbar-next]").click(function() {
- var tabGroup = jQuery(this).parents(".tobago-tabGroup:first");
- var selected = tabGroup.find(".tobago-tab-markup-selected");
- // the nearest of the next siblings, which are not disabled
- selected.nextAll(".nav-link:not(.disabled):first").click();
- });
-
- // init scroll position
- var header = tabGroups.find(".tobago-tabGroup-header");
- header.each(function() {
- Tobago.TabGroup.ensureScrollPosition(jQuery(this));
- });
-
- // tool tips
- tabGroups.each(function() {
- var tabGroup = jQuery(this);
- tabGroup.find(".tobago-tab").each(function() {
- var tab = jQuery(this);
- var tabContent = tabGroup.find(".tobago-tab-content[tabgroupindex=" + tab.attr("tabgroupindex") + "]");
- tabContent.attr("title", tab.attr("title"));
+ $tabGroups.each(function () {
+ var $tabGroup = jQuery(this);
+ var $hiddenInput = $tabGroup.find("> input[type=hidden]");
+
+ $tabGroup.find(".tobago-tabGroup-header:first .tobago-tab .nav-link:not(.disabled)").click(function () {
+ var $navLink = jQuery(this);
+ var $tab = $navLink.parent(".tobago-tab");
+
+ $hiddenInput.val($tab.attr("tabgroupindex"));
+
+ //remove data-markup, markup-css-class and .active
+ $tabGroup.find(".tobago-tab .nav-link.active").each(function () {
+ var $navLink = jQuery(this);
+ var $tab = $navLink.parent(".tobago-tab");
+
+ Tobago.Utils.removeDataMarkup($tab, markupString);
+ $tab.removeClass(markupCssClass);
+ $navLink.removeClass("active");
+ });
+
+ //add data-markup, markup-css-class and .active
+ Tobago.Utils.addDataMarkup($tab, markupString);
+ $tab.addClass(markupCssClass);
+ $navLink.addClass("active");
});
});
-
-
- // XXX hack for webkit to avoid scrollbars in box
-// jQuery('.tobago-tabGroup').hide();
-// jQuery('.tobago-tabGroup').show();
-};
-
-Tobago.TabGroup.ensureScrollPosition = function (header) {
- var tab = header.find(".tobago-tab-markup-selected");
- if (tab.length > 0) {
- var tabRight = tab.position().left + tab.outerWidth() - header.outerWidth();
- if (tabRight > 0) {
- header.scrollLeft(header.scrollLeft() + tabRight + 1); // +1 to avoid rounding problems
- }
- var tabLeft = tab.position().left;
- if (tabLeft < 0) {
- header.scrollLeft(header.scrollLeft() + tabLeft);
- }
- }
};
Tobago.registerListener(Tobago.TabGroup.init, Tobago.Phase.DOCUMENT_READY);
diff --git a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-utils.js b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-utils.js
index b7e3ad9..32318d2 100644
--- a/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-utils.js
+++ b/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/resources/tobago/standard/tobago-bootstrap/_version/js/tobago-utils.js
@@ -22,14 +22,14 @@ Tobago.Utils = {};
* @param id A JSF client id, type=string. Example: escapeClientId("page:input") -> "#page\\:input"
* @return A string which can be used as a jQuery selector.
*/
-Tobago.Utils.escapeClientId = function(id) {
+Tobago.Utils.escapeClientId = function (id) {
return '#' + id.replace(/([:\.])/g, '\\$1');
};
/**
* @deprecated since Tobago 2.0.5 because of misspelling
*/
-Tobago.Utils.selectWidthJQuery = function(elements, selector) {
+Tobago.Utils.selectWidthJQuery = function (elements, selector) {
return Tobago.Utils.selectWithJQuery(elements, selector);
};
@@ -39,17 +39,17 @@ Tobago.Utils.selectWidthJQuery = function(elements, selector) {
* @param elements a jQuery object to initialize (ajax) or null for initializing the whole document (full load).
* @param selector a jQuery selector.
*/
-Tobago.Utils.selectWithJQuery = function(elements, selector) {
+Tobago.Utils.selectWithJQuery = function (elements, selector) {
return elements == null
? jQuery(selector)
: elements.find(selector).add(elements.filter(selector));
};
-Tobago.Utils.findSubComponent = function(element, subId) {
+Tobago.Utils.findSubComponent = function (element, subId) {
return jQuery(Tobago.Utils.getSubComponentId(element.attr('id'), subId));
};
-Tobago.Utils.getSubComponentId = function(id, subId) {
+Tobago.Utils.getSubComponentId = function (id, subId) {
if (id != null) {
return "#" + id.replace(/:/g, "\\:") + "\\:\\:" + subId;
} else {
@@ -58,11 +58,11 @@ Tobago.Utils.getSubComponentId = function(id, subId) {
};
/** @deprecated */
-Tobago.Utils.findSuperComponent = function(element) {
+Tobago.Utils.findSuperComponent = function (element) {
return jQuery(Tobago.Utils.getSuperComponentId(element.attr('id')));
};
-Tobago.Utils.getSuperComponentId = function(id) {
+Tobago.Utils.getSuperComponentId = function (id) {
return "#" + id.substring(0, id.lastIndexOf("::")).replace(/:/g, "\\:");
};
@@ -102,8 +102,8 @@ Tobago.Utils.getNamingContainerId = function (id) {
* fix position, when the element it is outside of the current page
* @param elements is an jQuery Array of elements to be fixed.
*/
-Tobago.Utils.keepElementInVisibleArea = function(elements) {
- elements.each(function() {
+Tobago.Utils.keepElementInVisibleArea = function (elements) {
+ elements.each(function () {
var element = jQuery(this);
var page = jQuery(".tobago-page-content:first");
var left = element.offset().left;
@@ -117,7 +117,36 @@ Tobago.Utils.keepElementInVisibleArea = function(elements) {
};
/** @deprecated */
-Tobago.Utils.acceleratorKeyEvent = function() {
+Tobago.Utils.acceleratorKeyEvent = function () {
return Tobago.browser.isWebkit || Tobago.browser.isGecko ? 'keydown' : 'keypress';
};
+Tobago.Utils.addDataMarkup = function (element, markupString) {
+ var dataTobagoMarkup = element.attr("data-tobago-markup");
+ if (dataTobagoMarkup !== undefined) {
+ var markups = jQuery.parseJSON(dataTobagoMarkup);
+ markups.push(markupString);
+ element.attr("data-tobago-markup", JSON.stringify(markups));
+ } else {
+ element.attr("data-tobago-markup", JSON.stringify(markupString));
+ }
+};
+
+Tobago.Utils.removeDataMarkup = function (element, markupString) {
+ var dataTobagoMarkup = element.attr("data-tobago-markup");
+ if (dataTobagoMarkup !== undefined) {
+ var markups = jQuery.parseJSON(dataTobagoMarkup);
+ var index = jQuery.inArray(markupString, markups);
+ if (index >= 0) {
+ markups.splice(index, 1);
+ } else if (markups === markupString) {
+ markups = [];
+ }
+
+ if (markups.length > 0) {
+ element.attr("data-tobago-markup", JSON.stringify(markups));
+ } else {
+ element.removeAttr("data-tobago-markup");
+ }
+ }
+};
--
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.