Author: pyaschenko
Date: 2010-02-04 08:57:17 -0500 (Thu, 04 Feb 2010)
New Revision: 16410
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/jquery.position.js
Log:
fixes, cropPx was removed, optimization
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/jquery.position.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/jquery.position.js 2010-02-04
12:29:29 UTC (rev 16409)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/jquery.position.js 2010-02-04
13:57:17 UTC (rev 16410)
@@ -4,7 +4,20 @@
// TODO: clear code
// TODO: optimization
-//
+// jQuery(target).position(source,[params])
+// source:
+// jQuery selector
+// object {id:}
+// object {left:,top:,width:,height} // all properties are optimal
+// jQuery object
+// dom element
+// event
+//
+// params:
+// collision: string // not implemented
+// offset: array [x,y] // implemented only for noPositionType
+// from: string // place target relative of source
+// to: string // direction for target
(function($) {
$.fn.position = function(source, params) {
@@ -14,8 +27,9 @@
if (source.type) {
rect = getPointerRect(source);
} else if (stype == "string" || source.nodeType || source instanceof jQuery)
{
- stype = "element";
rect = getElementRect(source);
+ } else if (source.id) {
+ rect = getElementRect(document.getElementById(source.id));
} else {
rect = source;
}
@@ -58,15 +72,6 @@
}*/
$.PositionTypes[type] = options;
}
-
- function cropPx(value) {
- if (typeof value == "string") {
- if (!isNaN(value)) {
- return parseInt(value);
- }
- }
- return NaN;
- };
function getPointerRect (event) {
var e = $.event.fix(event);
@@ -229,19 +234,19 @@
rect.width = rect.width || 0;
rect.height = rect.height || 0;
- var left = cropPx(element.css('left'));
+ var left = parseInt(element.css('left'),10);
if (isNaN(left)) {
left = 0;
element.css('left', '0px');
}
rect.left = rect.left || left;
- var top = cropPx(element.css('top'));
+ var top = parseInt(element.css('top'),10);
if (isNaN(top)) {
top = 0;
element.css('top', '0px');
}
- rect.top = rect.top || top;
+ rect.top = rect.top || top;
var elementOffset = element.offset();
var pos = {};
@@ -257,10 +262,15 @@
pos = calculatePosition(rect, options.offset, winRect, {width:width, height:height},
options);
}
- pos.left -= elementOffset.left;
- pos.top -= elementOffset.top;
+ //pos.left -= elementOffset.left;
+ //pos.top -= elementOffset.top;
- element.css('left', (pos.left + 'px')).css('top', (pos.top +
'px'));
+ if (left!=pos.left) {
+ element.css('left', (pos.left + 'px'));
+ }
+ if (top!=pos.top) {
+ element.css('top', (pos.top + 'px'));
+ }
};
})(jQuery);
Show replies by date