You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/11/01 09:46:12 UTC
svn commit: r1195871 - in
/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard: ./
src/main/resources/META-INF/
src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/
Author: lofwyr
Date: Tue Nov 1 08:46:12 2011
New Revision: 1195871
URL: http://svn.apache.org/viewvc?rev=1195871&view=rev
Log:
TOBAGO-1046: Position of Popup and DatePicker should automatically fixed
- also putting JavaScript utils in its own source file
Added:
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-utils.js
- copied, changed from r1195851, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
Modified:
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/pom.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/pom.xml?rev=1195871&r1=1195870&r2=1195871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/pom.xml (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/pom.xml Tue Nov 1 08:46:12 2011
@@ -60,7 +60,7 @@
<configuration>
<target>
<concat destfile="${project.build.directory}/javascript-min/standard/script/tobago.min.js">
- <filelist dir="${basedir}/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script" files="tobago.js,calendar.js,dateConverter.js,tobago-menu.js,tobago-sheet.js" />
+ <filelist dir="${basedir}/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script" files="tobago.js,calendar.js,dateConverter.js,tobago-menu.js,tobago-sheet.js,tobago-utils.js" />
</concat>
<concat destfile="${project.build.directory}/javascript-min/msie_6_0/script/tobago.min.js">
<filelist dir="${basedir}/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/msie_6_0/script" files="tobago.js" />
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml?rev=1195871&r1=1195870&r2=1195871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-config.xml Tue Nov 1 08:46:12 2011
@@ -343,6 +343,7 @@
<script name="script/dateConverter.js"/>
<script name="script/tobago-menu.js"/>
<script name="script/tobago-sheet.js"/>
+ <script name="script/tobago-utils.js"/>
<script name="script/jquery-ui/1_7_2/ui.core.min.js"/>
<script name="script/jquery-ui/1_7_2/ui.draggable.min.js"/>
<script name="script/logging.js"/>
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js?rev=1195871&r1=1195870&r2=1195871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js Tue Nov 1 08:46:12 2011
@@ -309,30 +309,9 @@ jQuery.tobagoMenuParent = function(eleme
var ol = jQuery(this);
if (ol.attr('id').lastIndexOf("::") >= 0) {
return Tobago.Utils.findSuperComponent(ol);
- }
- return ol;
}
+ return ol;
+ }
});
})(jQuery);
-Tobago.Utils = {};
-
-Tobago.Utils.findSubComponent = function(element, subId) {
- return jQuery(Tobago.Utils.getSubComponentId(element.attr('id'), subId));
-};
-
-Tobago.Utils.getSubComponentId = function(id, subId) {
- if (id != null) {
- return "#" + id.replace(/:/g, "\\:") + "\\:\\:" + subId;
- } else {
- return null;
- }
-};
-
-Tobago.Utils.findSuperComponent = function(element) {
- return jQuery(Tobago.Utils.getSuperComponentId(element.attr('id')));
-};
-
-Tobago.Utils.getSuperComponentId = function(id) {
- return "#" + id.substring(0, id.lastIndexOf("::")).replace(/:/g, "\\:");
-};
Copied: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-utils.js (from r1195851, myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-utils.js?p2=myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-utils.js&p1=myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js&r1=1195851&r2=1195871&rev=1195871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-menu.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-utils.js Tue Nov 1 08:46:12 2011
@@ -15,306 +15,6 @@
* limitations under the License.
*/
-/*
- jQuery code to manage the menu.
- The DOM structure looks like this:
- <html>
- <body>
- <form>
- <ol class="tobago-menuBar">
- <li class="tobago-menu-markup-top">
- <a id="m1">Menu 1</a>
- </li>
- <li class="tobago-menu-markup-top">
- <a id="m2">Menu 2</a>
- </li>
- ...
- </ol>
- <div class="tobago-page">
- // page content
- </div>
- <span ... </span>
- <div class="tobago-menu-store"> // container for the sub menus.
- <ol id="m1::menu">
----> insert iframe here
- <li class="tobago-menu">
- <a>Sub Menu 1.1</a>
- <ol>
----> insert iframe here
- <li class="tobago-menu">
- <a>Sub Sub Menu 1.1.1</a>
- </li>
- ...
- </div>
- </form>
- </body>
- </html>
- The menu items of the top level (id="m1") are connected to the sub menus of the store div (id="m1::menu").
- */
-
-Tobago.Menu = {};
-
-/*
- jQuery(this) is the "a" tag of a menu item.
- */
-Tobago.Menu.handelKey = function(event) {
-
- var handled = false;
-
- var code = event.which;
- if (code == 0) {
- code = event.keyCode;
- }
-
- switch (code) {
- case 27: // escape
- Tobago.Menu.closeAll();
- handled = true;
- break;
- case 37: // cursor left
- if (jQuery(this).parent().hasClass('tobago-menu-markup-top')) {
- jQuery(this).parent().prev('li').children('a').focus();
- } else if (jQuery(this).parent().parent().tobagoMenu_findParentMenu().parent().hasClass('tobago-menu-markup-top')) {
- jQuery(this).parent().parent().tobagoMenu_findParentMenu().parent().prev('li').children('a').focus();
- } else {
- jQuery(this).closest('ol').prev('a').focus();
- }
- handled = true;
- break;
- case 38: // cursor up
- if (jQuery(this).parent().hasClass('tobago-menu-markup-top')) {
- // nothing
- } else {
- jQuery(this).parent().prevAll('li').children('a').eq(0).focus();
- }
- handled = true;
- break;
- case 39: // cursor right
- if (jQuery(this).parent().hasClass('tobago-menu-markup-top')) {
- jQuery(this).parent().next('li').children('a').focus();
- } else if (jQuery(this).next('ol').size() > 0) {
- jQuery(this).next('ol').children(":nth-child(1)").children('a').focus();
- } else {
- jQuery(this).parents('ol:last').tobagoMenu_findParentMenu().parent().next('li').children('a').focus();
- }
- handled = true;
- break;
- case 40: // cursor down
- if (jQuery(this).parent().hasClass('tobago-menu-markup-top')) {
- jQuery(this).tobagoMenu_findSubMenu().children(":nth-child(1)").children('a').focus();
- } else {
- jQuery(this).parent().nextAll('li').children('a').eq(0).focus();
- }
- handled = true;
- break;
- default:
- break;
- }
- return !handled;
-};
-
-/*
- jQuery(this) is a <a> tag of a menu item.
-*/
-Tobago.Menu.open = function(event) {
-
- var li = jQuery(this).parent();
- var sub = jQuery(this).tobagoMenu_findSubMenu();
-
- // close menus in other branches
- li.siblings().children('a').tobagoMenu_findSubMenu().find('ol').andSelf().css('visibility', 'hidden');
-
- // close sub sub menu
- sub.children().find("ol").css('visibility', 'hidden');
-
- // open sub menu
- if (sub.size() > 0) {
- // compute position
- // XXX Todo: "compute position" is not perfect! Should be enhanced, especially for sub menus.
- // XXX The problem is, when the menu opens at the edge of the visual window.
- var left;
- var top;
- if (li.hasClass('tobago-menu-markup-top')) {
- // is top menu
- left = li.offset().left;
- top = li.offset().top + li.outerHeight();
- // fix menu position, when it is outside of the current page
- var page = jQuery(".tobago-page-content:first");
- left = Math.max(0, Math.min(left, page.outerWidth() - sub.outerWidth()));
- top = Math.max(0, Math.min(top, page.outerHeight() - sub.outerHeight()));
- } else {
- // is sub menu
- left = li.position().left + li.outerWidth();
- top = li.position().top - 1; // 1 = border-top
- // XXX todo: fix sub menu position, when it is outside of the page
- }
- sub.css('left', left);
- sub.css('top', top);
-
- // show
- sub.css('visibility', 'visible');
-
- // IE6 select-tag fix
- if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 6) {
- // sub.css('width', sub.width());
- // sub.css('height', sub.height());
- // sub.css('display', 'none');
- // sub.css('display', 'block');
- var iframe = sub.children("iframe:first");
- iframe.css('width', sub.outerWidth());
- iframe.css('height', sub.outerHeight());
- iframe.css('left', -(parseInt(sub.css('border-left-width'), 10) + parseInt(sub.css('padding-left'), 10)));
- iframe.css('top', -(parseInt(sub.css('border-top-width'), 10) + parseInt(sub.css('padding-top'), 10)));
- }
- }
-
- // old "hover" off
- li.siblings('.tobago-menu-markup-selected').removeClass("tobago-menu-markup-selected");
- sub.children('.tobago-menu-markup-selected').removeClass("tobago-menu-markup-selected");
- // "hover" on
- jQuery(this).parents('li').addClass("tobago-menu-markup-selected");
-};
-
-Tobago.Menu.closeAll = function() {
- jQuery(".tobago-menuBar").each(function() {
- Tobago.Menu.switchOff(jQuery(this));
- });
- return false;
-};
-
-/**
-* returns the browser specific event which should be used.
-*/
-function compatibleKeyEvent() {
- return jQuery.browser.msie || jQuery.browser.safari ? 'keydown' : 'keypress';
-}
-
-Tobago.Menu.mouseOver = function(event) {
- jQuery(this).children('a').focus();
- return false;
-};
-
-Tobago.Menu.switchOn = function(menuBar, menu) {
- menuBar.find('li') // direct menus
- .add(menuBar.find('li').children('a').tobagoMenu_findSubMenu().find('li')) // add sub menus
- .bind('mouseover', Tobago.Menu.mouseOver)
- .children('a')
- .bind('focus', Tobago.Menu.open)
- .bind(compatibleKeyEvent(), Tobago.Menu.handelKey);
- menu.children('a').focus();
- jQuery("body").bind('click', Tobago.Menu.closeAll);
- menuBar.data('menu-active', true); // write state back
-};
-
-Tobago.Menu.switchOff = function(menuBar) {
- menuBar.find("ol")
- .add(menuBar.find('li').children('a').tobagoMenu_findSubMenu().find('ol').andSelf())
- .css('visibility', 'hidden');
- menuBar.find('li').add(menuBar.find('li').children('a').tobagoMenu_findSubMenu().find('li'))
- .unbind('mouseover', Tobago.Menu.mouseOver)
- .children('a')
- .unbind('focus', Tobago.Menu.open)
- .unbind(compatibleKeyEvent(), Tobago.Menu.handelKey);
- jQuery("body").unbind('click', Tobago.Menu.closeAll);
- menuBar.find('.tobago-menu-markup-selected').removeClass("tobago-menu-markup-selected");
- menuBar.data('menu-active', false); // write state back
-};
-
-/**
- * @param elements a jQuery object to initialize (ajax) or null for initializing the whole document (full load).
- */
-Tobago.Menu.init = function(elements) {
-
- var menus = Tobago.selectWidthJQuery(elements, ".tobago-menu-markup-top");
-
- // a click on the top menu make the complete menu active or inactive respectively.
- menus.click(function(event) {
-
- // e. g. disabled by a popup
- if (jQuery(this).children("a").data("disabled")) {
- return;
- }
- // register on click handlers
- var menuBar = jQuery(this).parent();
- var wasActive = menuBar.data('menu-active'); // read state
-
- if (wasActive) {
- Tobago.Menu.switchOff(menuBar);
- } else {
- Tobago.Menu.switchOn(menuBar, jQuery(this));
- }
-
- event.stopPropagation();
- });
-
- // IE6 select-tag fix
- // put a iframe inside the div, so that a <select> tag doesn't shine through.
- // the iframe must be resized (see above)
- if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) <= 6) {
- menus.children("ol").prepend(
- "<iframe class='tobago-menu-ie6bugfix' src='" + Tobago.blankPage + "'></iframe>");
- }
-
- jQuery(".tobago-page-menuStore").append(menus.children("ol"));
-
- var toolBarMenu = Tobago.selectWidthJQuery(
- elements, ".tobago-toolBar-menu .tobago-boxToolBar-menu .tobago-tabGroupToolBar-menu");
- // a click on toolBar menu opener -> forward to .tobago-menu-markup-top
- toolBarMenu.click(function(event) {
- jQuery(this).next().find('a').click();
- event.stopPropagation();
- });
-
- // init context menus
- var contextMenu = Tobago.selectWidthJQuery(elements, ".tobago-menu-contextMenu");
- contextMenu.parent().bind("contextmenu", function(event) {
- jQuery(this).children(".tobago-menu-contextMenu").find('a').click();
- event.stopPropagation();
- return false;
- });
-
-};
-
-jQuery.tobagoMenuParent = function(element) {
- var result = [];
-
- result.push(element);
-
- return result;
-};
-
-/*
- jQuery(this) is a list of "a" element of a menu item as jQuery object.
- Returns a list of "ol" objects. All sub menus as jQuery object.
-*/
-(function(jQuery) {
- jQuery.fn.extend({
- tobagoMenu_findSubMenu: function() {
- var menu = jQuery(this).next("ol");
- jQuery(this).each(function() {
- menu = menu.add(Tobago.Utils.findSubComponent(jQuery(this), "menu"));
- });
- return menu;
- }
- });
-})(jQuery);
-
-/*
- jQuery(this) is a "ol" element which represents a sub menu.
- returns the "a" element connected with the given sub menu.
-*/
-(function(jQuery) {
- jQuery.fn.extend({
- tobagoMenu_findParentMenu: function() {
- var ol = jQuery(this);
- if (ol.attr('id').lastIndexOf("::") >= 0) {
- return Tobago.Utils.findSuperComponent(ol);
- }
- return ol;
- }
- });
-})(jQuery);
-
Tobago.Utils = {};
Tobago.Utils.findSubComponent = function(element, subId) {
@@ -334,5 +34,23 @@ Tobago.Utils.findSuperComponent = functi
};
Tobago.Utils.getSuperComponentId = function(id) {
- return "#" + id.substring(0, id.lastIndexOf("::")).replace(/:/g, "\\:");
+ return "#" + id.substring(0, id.lastIndexOf("::")).replace(/:/g, "\\:");
+};
+
+/**
+ * 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() {
+ var element = jQuery(this);
+ var page = jQuery(".tobago-page-content:first");
+ var left = element.offset().left;
+ var top = element.offset().top;
+ // fix menu position, when it is outside of the current page
+ left = Math.max(0, Math.min(left, page.outerWidth() - element.outerWidth()));
+ top = Math.max(0, Math.min(top, page.outerHeight() - element.outerHeight()));
+ element.css('left', left);
+ element.css('top', top);
+ });
};
Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=1195871&r1=1195870&r2=1195871&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Tue Nov 1 08:46:12 2011
@@ -855,6 +855,8 @@ var Tobago = {
*/
setupPopup: function() {
+ Tobago.Utils.keepElementInVisibleArea(jQuery(".tobago-popup"));
+
// TODO: remove later (after change AJAX, that they replace tags instead of fill them...)
jQuery('.tobago-popup-parent > .tobago-popup').unwrap();