Author: nbelaevski
Date: 2008-08-13 20:06:11 -0400 (Wed, 13 Aug 2008)
New Revision: 10078
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
Log:
https://jira.jboss.org/jira/browse/RF-2543
https://jira.jboss.org/jira/browse/RF-3834
Modified:
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java
===================================================================
---
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-08-13
17:36:11 UTC (rev 10077)
+++
trunk/ui/suggestionbox/src/main/java/org/richfaces/renderkit/html/SuggestionBoxRenderer.java 2008-08-14
00:06:11 UTC (rev 10078)
@@ -87,9 +87,11 @@
*/
private final InternetResource[] additionalScripts = {
new org.ajax4jsf.javascript.PrototypeScript(),
+ getResource("/org/richfaces/renderkit/html/scripts/jquery/jquery.js"),
getResource("/org/richfaces/renderkit/html/scripts/available.js"),
new org.ajax4jsf.javascript.SmartPositionScript(),
getResource("/org/richfaces/renderkit/html/scripts/browser_info.js"),
+ getResource("/org/richfaces/renderkit/html/scripts/utils.js"),
getResource("/org/richfaces/renderkit/html/scripts/scriptaculous/effects.js"),
getResource("scripts/suggestionbox.js")};
Modified:
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js
===================================================================
---
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-08-13
17:36:11 UTC (rev 10077)
+++
trunk/ui/suggestionbox/src/main/resources/org/richfaces/renderkit/html/scripts/suggestionbox.js 2008-08-14
00:06:11 UTC (rev 10078)
@@ -116,6 +116,21 @@
this.onBlurListener = this.onBlur.bindAsEventListener(this);
Event.observe(this.element, "blur", this.onBlurListener);
+ //IE only
+ if (RichFaces.navigatorType() == RichFaces.MSIE) {
+ Event.observe(this.element, "focusout", function(event) {
+ var elt = event.toElement;
+ while (elt) {
+ if (elt == this.update) {
+ this.element.keepFocus = true;
+ elt = undefined;
+ } else {
+ elt = elt.parentNode;
+ }
+ }
+ }.bindAsEventListener(this));
+ }
+
this.onKeyDownListener = this.onKeyDown.bindAsEventListener(this);
Event.observe(this.element, "keydown", this.onKeyDownListener);
@@ -431,32 +446,17 @@
},
onBlur: function(event) {
- if (this.isUnloaded()) return;
+ if (this.isUnloaded()) return;
this.wasBlur = true;
if (!this.active) return;
- var offsets = RichFaces.Position.calcOffsets(this.update);
- if (RichFaces.navigatorType() != RichFaces.MSIE) {
- offsets["x"] = 0;
- offsets["y"] = 0;
+ if (this.element.keepFocus) {
+ this.element.keepFocus = false;
+ this.element.focus();
+ } else {
+ // needed to make click events working
+ setTimeout(this.hide.bind(this), 250);
}
-
- var x = event.clientX +
- document.body.scrollLeft +
- document.documentElement.scrollLeft;
-
- var y = event.clientY +
- document.body.scrollTop+
- document.documentElement.scrollTop;
-
- if (x > offsets["x"] && x < (this.update.clientWidth +
offsets["x"])) {
- if (y > (offsets["y"] - this.update.clientHeight) && y
< offsets["y"]) {
- this.element.focus();
- return;
- }
- }
- // needed to make click events working
- setTimeout(this.hide.bind(this), 250);
},
onScroll: function(event) {
@@ -998,7 +998,6 @@
this.source = $(source);
this.target = $(target);
- var targetStyle = {};
/*
http://jira.exadel.com/browse/RFA-236
@@ -1012,15 +1011,11 @@
}
*/
- var offsets = this.calcOffsets(this.source);
+ this.clonePosition(this.target, this.source, this.source.offsetHeight);
- Element.setStyle(this.target, Object.extend({"left":
(offsets["x"])
- + "px", "top": (offsets["y"]) +
"px"}, targetStyle));
-
if (options.iframeId) {
var iframe = $(options.iframeId);
var zindexVar = options.zindex ? options.zindex : 200 ;
- Position.clone(this.target, iframe);
Element.setStyle(this.target, {zIndex: zindexVar + 1});
Element.setStyle(iframe, {zIndex: zindexVar});
@@ -1032,93 +1027,36 @@
}
},
- cumulativeOffset: function(element) {
- var valueT = 0, valueL = 0;
- var fixedFlag = false;
- do {
- if (fixedFlag) {
- fixedFlag = false;
- valueT += element.scrollTop || 0;
- valueL += element.scrollLeft || 0;
- }
- valueT += element.offsetTop || 0;
- valueL += element.offsetLeft || 0;
-
- var position = element.style['position'];
- if (!position && element.currentStyle) {
- position = element.currentStyle['position'];
- }
- else if (!position && document.defaultView &&
document.defaultView.getComputedStyle) {
- var css = document.defaultView.getComputedStyle(element, null);
- position = css ? css['position'] : null;
- }
- if (position == 'fixed') {
- fixedFlag= true;
- }
-
- element = element.offsetParent;
- } while (element);
- return [valueL, valueT];
- },
-
- calcOffsets : function(element) {
- var offsetBase = this.cumulativeOffset(element);
- return {x: offsetBase[0], y: element.offsetHeight + offsetBase[1]};
+ PX_REGEX: /px$/,
+
+ parseToPx: function(value) {
+ var v = value.strip();
+ if (v == 'auto') {
+ return 0;
+ } else {
+ return parseFloat(v.replace(this.PX_REGEX, ""));
+ }
},
+
+ clonePosition: function(target, source, vOffset) {
+ var jqt = jQuery(target);
+
+ var visibility = jqt.css('visibility');
+ var display = jqt.css('display');
+
+ var so = jQuery(source).offset();
+ var to = jqt.css({left: '0px', top: '0px', visibility:
'hidden', display: ''}).offset();
- _removePx : function(str) {
- str += "";
- if (str.indexOf("px") != -1) {
- return str.substr(0, str.indexOf("px"));
- }
- return str;
+ var l = so.left - to.left;
+ var p = so.top - to.top + vOffset;
+
+ // set position
+ target.style.left = l + 'px';
+ target.style.top = p + 'px';
+
+ jqt.css({visibility: visibility, display: display});
},
-
- calcHeight: function() {
- return this.options.height == "auto" ? ""
:this.options.height;
- },
-
- calcTop: function(targetHeight) {
- var sourceOffset = Position.cumulativeOffset(this.source);
- var sourceTop = sourceOffset[1];
- var sourceHeight = this.source.offsetHeight;
- var body = this.getBody();
- // if (sourceTop + sourceHeight + targetHeight <= body.clientHeight) {
- return sourceTop + sourceHeight - 1;
- },
-
- calcWidth: function() {
- if (this.options.width == "auto") {
- return "";
- } else {
- if (this.options.width.indexOf("%") >= 0) {
- // Count persents to pixels
- var percent = parseInt(this.options.width.substring(0,
this.options.width.indexOf("%")));
- var sizeInPixels = parseInt(this.source.offsetWidth) * percent
- / 100;
- this.options.width = sizeInPixels + "px";
- }
-
- return this.options.width;
- }
- // return this.source.offsetWidth;
- },
-
- calcLeft: function(targetWidth) {
- // Position.prepare();
- var sourceOffset = Position.cumulativeOffset(this.source);
- var sourceLeft = sourceOffset[0];
- var sourceWidth = this.source.offsetWidth;
- var body = this.getBody();
- var width = parseInt(sourceLeft) + parseInt(sourceWidth)
- + parseInt(targetWidth);
- if (width <= parseInt(body.clientWidth)) {
- return sourceLeft;
- } else {
- return width;
- }
- },
-
+
getBody: function() {
return this.source.ownerDocument.body;
}