[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-02-08 Thread B

worked like a charm :)

Thanks

On Feb 4, 7:05�pm, edwardbaafi [EMAIL PROTECTED] wrote:
 Here's an example using the hacked source that starts dragging one
 element when you click (mousedown) on another element. Notice the null
 value passed as the undocumented fn parameter:

 html xmlns=http://www.w3.org/1999/xhtml;head
 meta http-equiv=Content-Type content=text/html; charset=UTF-8 /
 titleProgrammatic Draggable/title
 script type=text/javascript src=../js/jquery.js/script
 script type=text/javascript src=../js/jquery.ui-1.0/
 jquery.dimensions.js/script
 script type=text/javascript src=../js/jquery.ui-1.0/ui.mouse.js/
 script
 script type=text/javascript src=../js/jquery.ui-1.0/
 ui.draggable.js/script
 script type=text/javascript src=../js/jquery.ui-1.0/
 ui.draggable.ext.js/script
 script type=text/javascript

 � � � � � � � �$(document).ready(function(){

 � � � � � � � � � //bind event for one fire
 � � � � � � � � � $(#programmatic).one(mousedown,
 � � � � � � � � � � � � � function(e){
 � � � � � � � � � � � � � � � � //make draggable element draggable
 � � � � � � � � � � � � � � � � $(#draggable).draggable();
 � � � � � � � � � � � � � � � � //trigger a mousedown to start a drag
 � � � � � � � � � � � � � � � � $(#draggable).trigger(mousedown,
 [],null,{srcElement:$
 (#draggable),which:e.which,pageX:e.pageX,pageY:e.pageY});
 � � � � � � � � � � � � � � � � });
 � � � � � � � � � � � � � });

 /script
 style type=text/css
 #draggable{

 width:100px;
 height:100px;
 background-color:#aa;}

 #programmatic{

 width:100px;
 height:100px;
 background-color:#00aa00;}

 /style
 /head
 body
 div id=draggabledraggable/div
 div id=programmaticby dragging here/div
 /body
 /html

 On Feb 4, 5:03 pm, B [EMAIL PROTECTED] wrote:

  Hi,
  I am trying to also trigger the draggable from within a javascript
  function. If possible can you please share your source hack.

  Thanks

  On Jan 29, 2:49 pm, edwardbaafi [EMAIL PROTECTED] wrote:

   http://docs.jquery.com/Eventshasmousedown, mouseup, mousemove, etc

   Yes, you are able to trigger these events using trigger( type,
   data ), but what about setting the event properties?

   In my case, when an element is draggable and it's mousedown event
   fires, the
   click function in ui.mouse.js is called.. �A number of properties of
   the event, like e.which, e.target, e.srcElement, e.pageX, e.pageY are
   needed but at least some of these properties are undefined..

   Is it possible to set these properties when calling
   trigger('mousedown') or with some other unpublished way?

   Thanks,

   Ed


[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-02-04 Thread B

Hi,

I am having the same problem with triggering the draggable from a
javascript function. If possible could you please share your source
hack?

Thanks

On Jan 29, 2:49 pm, edwardbaafi [EMAIL PROTECTED] wrote:
 http://docs.jquery.com/Eventshas mousedown, mouseup, mousemove, etc

 Yes, you are able to trigger these events using trigger( type,
 data ), but what about setting the event properties?

 In my case, when an element is draggable and it's mousedown event
 fires, the
 click function in ui.mouse.js is called..  A number of properties of
 the event, like e.which, e.target, e.srcElement, e.pageX, e.pageY are
 needed but at least some of these properties are undefined..

 Is it possible to set these properties when calling
 trigger('mousedown') or with some other unpublished way?

 Thanks,

 Ed


[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-02-04 Thread B

Hi,
I am trying to also trigger the draggable from within a javascript
function. If possible can you please share your source hack.

Thanks


On Jan 29, 2:49 pm, edwardbaafi [EMAIL PROTECTED] wrote:
 http://docs.jquery.com/Eventshas mousedown, mouseup, mousemove, etc

 Yes, you are able to trigger these events using trigger( type,
 data ), but what about setting the event properties?

 In my case, when an element is draggable and it's mousedown event
 fires, the
 click function in ui.mouse.js is called..  A number of properties of
 the event, like e.which, e.target, e.srcElement, e.pageX, e.pageY are
 needed but at least some of these properties are undefined..

 Is it possible to set these properties when calling
 trigger('mousedown') or with some other unpublished way?

 Thanks,

 Ed


[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-02-04 Thread edwardbaafi

Hi B,

I would think this is an important feature so the fact that you are
looking to do the same thing means I am not alone..  I'd like to
submit this as a feature but am still trying to figure out the state
of trigger's undocumented parameter fn:
http://groups.google.com/group/jquery-en/browse_thread/thread/ace02e1b78894fc2/1be5003cc4cd690c#1be5003cc4cd690c


The change is trivial but you have to change both the public trigger
function and the helper function (you'll find two trigger functions in
the jquery source)..  Because I don't know where the undocumented fn
param is used, I put my new eventsParam after that:

/* helper trigger function */
trigger: function(type, data, elem, donative, extra, eventParams) {
// Clone the incoming data, if any
data = jQuery.makeArray(data || []);

// Handle a global trigger
if ( !elem ) {
// Only trigger if we've ever bound an event for it
if ( this.global[type] )
jQuery(*).add([window, 
document]).trigger(type, data);

// Handle triggering a single element
} else {
// don't do events on text and comment nodes
if ( elem.nodeType == 3 || elem.nodeType == 8 )
return undefined;

var val, ret, fn = jQuery.isFunction( elem[ type ] || 
null ),
// Check to see if we need to provide a fake 
event, or not
event = !data[0] || !data[0].preventDefault;

// Pass along a fake event
if ( event ){
if(eventParams!=null){
eventParams.type = type;
eventParams.target= elem;
   data.unshift( this.fix(eventParams) );
}
else
   data.unshift( this.fix({ type: type,
target: elem }) );
   }
// Enforce the right trigger type
data[0].type = type;

// Trigger the event
if ( jQuery.isFunction( jQuery.data(elem, handle) ) )
val = jQuery.data(elem, handle).apply( elem, 
data );

// Handle triggering native .onfoo handlers
if ( !fn  elem[on+type]  elem[on+type].apply( 
elem, data )
=== false )
val = false;

// Extra functions don't get the custom event object
if ( event )
data.shift();

// Handle triggering of extra function
if ( extra  jQuery.isFunction( extra ) ) {
// call the extra function and tack the current 
return value on
the end for possible inspection
ret = extra.apply( elem, val == null ? data :
data.concat( val ) );
// if anything is returned, give it precedence 
and have it
overwrite the previous value
if (ret !== undefined)
val = ret;
}

// Trigger the native events (except for clicks on 
links)
if ( fn  donative !== false  val !== false  !
(jQuery.nodeName(elem, 'a')  type == click) ) {
this.triggered = true;
try {
elem[ type ]();
// prevent IE from throwing an error for some 
hidden elements
} catch (e) {}
}

this.triggered = false;
}

return val;
},


/* public trigger function*/
trigger: function( type, data, fn ,eventParams) {
return this.each(function(){
jQuery.event.trigger( type, data, this, true, 
fn,eventParams );
});
},



On Feb 4, 5:03 pm, B [EMAIL PROTECTED] wrote:
 Hi,
 I am trying to also trigger the draggable from within a javascript
 function. If possible can you please share your source hack.

 Thanks

 On Jan 29, 2:49 pm, edwardbaafi [EMAIL PROTECTED] wrote:

  http://docs.jquery.com/Eventshasmousedown, mouseup, mousemove, etc

  Yes, you are able to trigger these events using trigger( type,
  data ), but what about setting the event properties?

  In my case, when an element is draggable and it's mousedown event
  fires, the
  click function in ui.mouse.js is called..  A number of properties of
  the event, like e.which, e.target, e.srcElement, 

[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-02-04 Thread edwardbaafi

Here's an example using the hacked source that starts dragging one
element when you click (mousedown) on another element. Notice the null
value passed as the undocumented fn parameter:

html xmlns=http://www.w3.org/1999/xhtml;head
meta http-equiv=Content-Type content=text/html; charset=UTF-8 /
titleProgrammatic Draggable/title
script type=text/javascript src=../js/jquery.js/script
script type=text/javascript src=../js/jquery.ui-1.0/
jquery.dimensions.js/script
script type=text/javascript src=../js/jquery.ui-1.0/ui.mouse.js/
script
script type=text/javascript src=../js/jquery.ui-1.0/
ui.draggable.js/script
script type=text/javascript src=../js/jquery.ui-1.0/
ui.draggable.ext.js/script
script type=text/javascript

   $(document).ready(function(){

  //bind event for one fire
  $(#programmatic).one(mousedown,
  function(e){
//make draggable element draggable
$(#draggable).draggable();
//trigger a mousedown to start a drag
$(#draggable).trigger(mousedown,
[],null,{srcElement:$
(#draggable),which:e.which,pageX:e.pageX,pageY:e.pageY});
});
  });

/script
style type=text/css
#draggable{

width:100px;
height:100px;
background-color:#aa;
}
#programmatic{

width:100px;
height:100px;
background-color:#00aa00;
}
/style
/head
body
div id=draggabledraggable/div
div id=programmaticby dragging here/div
/body
/html

On Feb 4, 5:03 pm, B [EMAIL PROTECTED] wrote:
 Hi,
 I am trying to also trigger the draggable from within a javascript
 function. If possible can you please share your source hack.

 Thanks

 On Jan 29, 2:49 pm, edwardbaafi [EMAIL PROTECTED] wrote:

  http://docs.jquery.com/Eventshasmousedown, mouseup, mousemove, etc

  Yes, you are able to trigger these events using trigger( type,
  data ), but what about setting the event properties?

  In my case, when an element is draggable and it's mousedown event
  fires, the
  click function in ui.mouse.js is called..  A number of properties of
  the event, like e.which, e.target, e.srcElement, e.pageX, e.pageY are
  needed but at least some of these properties are undefined..

  Is it possible to set these properties when calling
  trigger('mousedown') or with some other unpublished way?

  Thanks,

  Ed


[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-01-29 Thread Glen Lipka
http://docs.jquery.com/Events has mousedown, mouseup, mousemove, etc

Also check out the plugins for draggables in UI.
http://docs.jquery.com/UI

Glen

On Jan 28, 2008 1:49 PM, edwardbaafi [EMAIL PROTECTED] wrote:


 Hi..

 Does anyone know how one could generate a mousedown event
 programmatically in order to cause a draggable to start
 dragging?

 I have a number of overlapping, absolutely positioned divs where
 certain sections of the background images are transparent..  What I
 need to do is to allow the user to drag the topmost div that is not
 transparent at the xy coord of the mouse down event..  What I'd like
 to do is to register for the mousedown event, iterate through all
 elements that overlap the xy coord, make the first one that isn't
 transparent at that point draggable, and fire a mousedown event on
 that element, starting the drag..

 For example, if you look at the diagram (ascii art) at the bottom of
 this message, there are two rectangles (may be distorted) with a small
 rectangle cut out of the middle of each..  One rectangle filled with
 # chars is above the other which is filled with  chars, but part
 of the  rect is visible behind the # rect.. The user needs to be
 able to drag the  rect by clicking through the hole in the #
 rect..  I have an in memory boundary representation of the filled
 rects, so I can query this to do the hit testing, but need a mechanism
 to start the dragging programmatically..  Generating a click event
 doesn't seem to work as this seems to fire after releasing the mouse
 where dragging occurs on mouse down..

 Any thoughts?

 Thanks.. -Ed

 
  
  
  
  
  
  
  



[jQuery] Re: Generating a Mousedown event programmatically - similar to click() generation..

2008-01-29 Thread edwardbaafi

 http://docs.jquery.com/Events has mousedown, mouseup, mousemove, etc


Yes, you are able to trigger these events using trigger( type,
data ), but what about setting the event properties?

In my case, when an element is draggable and it's mousedown event
fires, the
click function in ui.mouse.js is called..  A number of properties of
the event, like e.which, e.target, e.srcElement, e.pageX, e.pageY are
needed but at least some of these properties are undefined..

Is it possible to set these properties when calling
trigger('mousedown') or with some other unpublished way?

Thanks,

Ed