r2839 - + Updated positionTo parameter to accept a single object scope instead of individual para...

r2839 - + Updated positionTo parameter to accept a single object scope instead of individual para...


Author: vtGavin
Date: Thu Jun 25 09:16:39 2009
New Revision: 2839
Modified:
branches/dev/positionTo/demos/positionTo/default.html
branches/dev/positionTo/ui/utils.positionTo.js
Log:
+ Updated positionTo parameter to accept a single object scope instead of
individual parameters.
+ Offset now accepts a single value for both horizontal and vertical
offsets.
Modified: branches/dev/positionTo/demos/positionTo/default.html
==============================================================================
--- branches/dev/positionTo/demos/positionTo/default.html    (original)
+++ branches/dev/positionTo/demos/positionTo/default.html    Thu Jun 25
09:16:39 2009
@@ -49,12 +49,12 @@
$('select#positionTo_targetAnchor_horizontal
option:selected').val() + ' '
+ $('select#positionTo_targetAnchor_vertical
option:selected').val();
- $('div#positionTo_positionable').positionTo(
- $('div#positionTo_parent')[0],
- positionableAnchor,
- targetAnchor,
- $('input#positionTo_offset').val()
- );
+ $('div#positionTo_positionable').positionTo({
+ of: $('div#positionTo_parent')[0],
+ my: positionableAnchor,
+ at: targetAnchor,
+ offset: $('input#positionTo_offset').val()
+ });
});
    });
    </script>
Modified: branches/dev/positionTo/ui/utils.positionTo.js
==============================================================================
--- branches/dev/positionTo/ui/utils.positionTo.js    (original)
+++ branches/dev/positionTo/ui/utils.positionTo.js    Thu Jun 25 09:16:39 2009
@@ -7,19 +7,43 @@
*
* TODO: create document page for positionTo and add link here
*/
-$.fn.positionTo = function(of, my, at, offset){    
-    // set default values for unset parameters
-    offset = typeof(offset) != 'undefined' ? offset : '0 0';
-    
+$.fn.positionTo = function(options){
+ // set default values
+ var defaults = {
+ my: 'left top',
+ at: 'left bottom',
+ offset: '0 0',
+ collisionDetect: 'flip',
+ stackFix: true
+ };
+
+ // add in defaults for any unspecified values
+ options = $.extend({}, defaults, options);
+
+ // if: the element to position against was not specified
+ // then: we can't proceed with positioning, return an error condition
+ if (options.of === undefined)
+ {
+ return false;
+ }
+
// !!! TODO: create a page resize handler to adjust the absolute
position of the positionable elements
- var positionTo_handlers = {
+ var handlers = {
resize: function(){
-         // !!! TODO: implement mouse following
+         // !!! TODO: implement page resizing handler
}
};
- var $targetElem = $(of),
- targetPosition = $targetElem.offset();
+ var $targetElem = $(options.of);
+
+ // if: the specified target selector (of) does not resolve to an
element in the DOM
+ // then: return an error condition
+ if ($targetElem.length <= 0)
+ {
+ return false;
+ }
+
+ var targetPosition = $targetElem.offset();
// if: a parent node exists for the target node
// then: estimate the target node's position by comparing their
relative absolute offsets
@@ -45,9 +69,9 @@
var positionableOffset_x = 0,
positionableOffset_y = 0,
- array_positionableAnchor_chunks = my.split(' '),
- array_targetAnchor_chunks = at.split(' '),
- array_offset_chunks = offset.replace(/px/gi, '').split(' ');
+ array_positionableAnchor_chunks = options.my.split(' '),
+ array_targetAnchor_chunks = options.at.split(' '),
+ array_offset_chunks =
options.offset.replace(/px/gi, '').split(' ');
if (array_positionableAnchor_chunks.length == 2)
{     
@@ -120,6 +144,17 @@
    {
        positionableOffset_y += offset_vertical_px;
    }
+ }
+ else if (array_offset_chunks.length == 1)
+ {
+ var offset_px = parseInt(array_offset_chunks[0]);
+ // if: a valid integer was specified for the offset
+ // then: apply it to the calculated horizontal and vertical offsets
+ if (!isNaN(offset_px))
+ {
+ positionableOffset_x += offset_px;
+ positionableOffset_y += offset_px;
+ }
}
this.css('left', (targetPosition.left + positionableOffset_x) + 'px')