On 9/5/06, Marc Boeren <[EMAIL PROTECTED]> wrote:
>
> Hiyall,
>
> If I just want to change the x-position or the height of an element, I
> can't use the setElementPosition/Dimensions function. How about an API
> extension where you can pass null for an argument and that argument
> will not be updated? (another option would be to add setElementHeight
> and setElementWidth).
>
> Simple usage example in an onresize handler:
>
>   setElementDimensions(fixedwidthelement,
>                        {w:null, h: getViewportDimensions().h});
>
> Implementation (based on current setElementPosition):
>
> setElementPosition = function (elem, newPos/* optional */, units) {
>     elem = MochiKit.DOM.getElement(elem);
>     if (typeof(units) == 'undefined') {
>         units = 'px';
>     }
>     var style = {};
>     if (newPos.x!==null) style.left = newPos.x + units;
>     if (newPos.y!==null) style.top = newPos.y + units;
>     MochiKit.DOM.updateNodeAttributes(elem, {'style': style});
> };
>
> Same for setElementDimension.
>
> I can supply a patch if anyone is interested.
>
> Ciao, Marc.

+1

I'd also like to see relative versions of those functions, would help
with custom dragging and resizing. I.e. adjustElementPosition(el, {x:
0, y: -10}) would move the element 10pxls up.

Not to be pushy, but I'd also like to see "add" and "subtract" member
functions on the dimension and coordinates objects.

Now, this:
var delta = new MochiKit.DOM.Coordinates(e.mouse().page.x - lastpos.x,
                                         e.mouse().page.y - lastpos.y);
lastpos = e.mouse().page;
currelpos = elementPosition(pi.firstChild);
var newpos = new MochiKit.DOM.Coordinates(currelpos.x + delta.x,
                                          currelpos.y + delta.y);
setElementPosition(pi.firstChild, newpos);

would be reduced to this:
var delta = e.mouse().page.subtract(lastpos);
lastpos = e.mouse().page;
adjustElementPosition(pi.firstChild, delta);

I'd be happy to provide patches for this if anyone else has use for it.

Arnar

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to