xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / bean / support / syn / synthetic.js

24.1 KB
1(function(){
2var extend = function(d, s) { for (var p in s) d[p] = s[p]; return d;},
3	// only uses browser detection for key events
4	browser = {
5		msie:     !!(window.attachEvent && !window.opera),
6		opera:  !!window.opera,
7		webkit : navigator.userAgent.indexOf('AppleWebKit/') > -1,
8		safari: navigator.userAgent.indexOf('AppleWebKit/') > -1 && navigator.userAgent.indexOf('Chrome/') == -1,
9		gecko:  navigator.userAgent.indexOf('Gecko') > -1,
10		mobilesafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/),
11		rhino : navigator.userAgent.match(/Rhino/) && true
12	},
13	createEventObject = function(type, options, element){
14		var event = element.ownerDocument.createEventObject();
15		return extend(event, options);
16	},
17	data = {}, 
18	id = 1, 
19	expando = "_synthetic"+(new Date() - 0),
20	bind,
21	unbind,
22	key = /keypress|keyup|keydown/,
23	page = /load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll/,
24	//this is maintained so we can click on html and blur the active element
25	activeElement,
26
27/**
28 * @class Syn
29 * @download funcunit/dist/syn.js
30 * @test funcunit/synthetic/qunit.html
31 * Syn is used to simulate user actions.  It creates synthetic events and
32 * performs their default behaviors.
33 * 
34 * <h2>Basic Use</h2>
35 * The following clicks an input element with <code>id='description'</code>
36 * and then types <code>'Hello World'</code>.
37 * 
38@codestart
39Syn.click({},'description')
40  .type("Hello World")
41@codeend
42 * <h2>User Actions and Events</h2>
43 * <p>Syn is typically used to simulate user actions as opposed to triggering events. Typing characters
44 * is an example of a user action.  The keypress that represents an <code>'a'</code>
45 * character being typed is an example of an event. 
46 * </p>
47 * <p>
48 *   While triggering events is supported, it's much more useful to simulate actual user behavior.  The 
49 *   following actions are supported by Syn:
50 * </p>
51 * <ul>
52 *   <li><code>[Syn.prototype.click click]</code> - a mousedown, focus, mouseup, and click.</li>
53 *   <li><code>[Syn.prototype.dblclick dblclick]</code> - two <code>click!</code> events followed by a <code>dblclick</code>.</li>
54 *   <li><code>[Syn.prototype.key key]</code> - types a single character (keydown, keypress, keyup).</li>
55 *   <li><code>[Syn.prototype.type type]</code> - types multiple characters into an element.</li>
56 *   <li><code>[Syn.prototype.move move]</code> - moves the mouse from one position to another (triggering mouseover / mouseouts).</li>
57 *   <li><code>[Syn.prototype.drag drag]</code> - a mousedown, followed by mousemoves, and a mouseup.</li>
58 * </ul>
59 * All actions run asynchronously.  
60 * Click on the links above for more 
61 * information on how to use the specific action.
62 * <h2>Asynchronous Callbacks</h2>
63 * Actions don't complete immediately. This is almost 
64 * entirely because <code>focus()</code> 
65 * doesn't run immediately in IE.
66 * If you provide a callback function to Syn, it will 
67 * be called after the action is completed.
68 * <br/>The following checks that "Hello World" was entered correctly: 
69@codestart
70Syn.click({},'description')
71  .type("Hello World", function(){
72  
73  ok("Hello World" == document.getElementById('description').value)  
74})
75@codeend
76<h2>Asynchronous Chaining</h2>
77<p>You might have noticed the [Syn.prototype.then then] method.  It provides chaining 
78so you can do a sequence of events with a single (final) callback.  
79</p><p>
80If an element isn't provided to then, it uses the previous Syn's element.
81</p>
82The following does a lot of stuff before checking the result:
83@codestart
84Syn.type('ice water','title')
85  .type('ice and water','description')
86  .click({},'create')
87  .drag({to: 'favorites'},'newRecipe',
88    function(){
89      ok($('#newRecipe').parents('#favorites').length);
90    })
91@codeend
92
93<h2>jQuery Helper</h2>
94If jQuery is present, Syn adds a triggerSyn helper you can use like:
95@codestart
96$("#description").triggerSyn("type","Hello World");
97@codeend
98 * <h2>Key Event Recording</h2>
99 * <p>Every browser has very different rules for dispatching key events.  
100 * As there is no way to feature detect how a browser handles key events,
101 * synthetic uses a description of how the browser behaves generated
102 * by a recording application.  </p>
103 * <p>
104 * If you want to support a browser not currently supported, you can
105 * record that browser's key event description and add it to
106 * <code>Syn.key.browsers</code> by it's navigator agent.
107 * </p>
108@codestart
109Syn.key.browsers["Envjs\ Resig/20070309 PilotFish/1.2.0.10\1.6"] = {
110  'prevent':
111    {"keyup":[],"keydown":["char","keypress"],"keypress":["char"]},
112  'character':
113    { ... }
114}
115@codeend
116 * <h2>Limitations</h2>
117 * Syn fully supports IE 6+, FF 3+, Chrome, Safari, Opera 10+.
118 * With FF 1+, drag / move events are only partially supported. They will
119 * not trigger mouseover / mouseout events.<br/>
120 * Safari crashes when a mousedown is triggered on a select.  Syn will not 
121 * create this event.
122 * <h2>Contributing to Syn</h2>
123 * Have we missed something? We happily accept patches.  The following are 
124 * important objects and properties of Syn:
125 * <ul>
126 * 	<li><code>Syn.create</code> - contains methods to setup, convert options, and create an event of a specific type.</li>
127 *  <li><code>Syn.defaults</code> - default behavior by event type (except for keys).</li>
128 *  <li><code>Syn.key.defaults</code> - default behavior by key.</li>
129 *  <li><code>Syn.keycodes</code> - supported keys you can type.</li>
130 * </ul>
131 * <h2>Roll Your Own Functional Test Framework</h2>
132 * <p>Syn is really the foundation of JavaScriptMVC's functional testing framework - [FuncUnit].
133 *   But, we've purposely made Syn work without any dependencies in the hopes that other frameworks or 
134 *   testing solutions can use it as well.
135 * </p>
136 * @constructor 
137 * Creates a synthetic event on the element.
138 * @param {Object} type
139 * @param {Object} options
140 * @param {Object} element
141 * @param {Object} callback
142 * @return Syn
143 */
144Syn = function(type, options, element, callback){		
145	return ( new Syn.init(type, options, element, callback) )
146};
147
148bind = function(el, ev, f){
149	return el.addEventListener ? 
150		el.addEventListener(ev, f, false) : 
151		 el.attachEvent("on"+ev, f) 
152};
153unbind = function(el, ev, f){
154	return el.addEventListener ?
155		el.removeEventListener(ev, f, false) :
156		el.detachEvent("on"+ev, f) 
157};
158
159/**
160 * @Static
161 */	
162extend(Syn,{
163	/**
164	 * Creates a new synthetic event instance
165	 * @hide
166	 * @param {Object} type
167	 * @param {Object} options
168	 * @param {Object} element
169	 * @param {Object} callback
170	 */
171	init: function( type, options, element, callback ) {
172		var args = Syn.args(options,element, callback),
173			self = this;
174		this.queue = [];
175		this.element = args.element;
176		
177		//run event
178		if(typeof this[type] == "function") {
179			this[type](args.options, args.element, function(defaults,el ){
180				args.callback && args.callback.apply(self, arguments);
181				self.done.apply(self, arguments)		
182			})
183		}else{
184			this.result = Syn.trigger(type, args.options, args.element);
185			args.callback && args.callback.call(this, args.element, this.result);
186		}
187	},
188	jquery: function( el, fast ) {
189		if(window.FuncUnit && window.FuncUnit.jquery){
190			return window.FuncUnit.jquery
191		} if (el){
192			return Syn.helpers.getWindow(el).jQuery || window.jQuery	
193		}
194		else{
195			return window.jQuery
196		}
197	},
198	/**
199	 * Returns an object with the args for a Syn.
200	 * @hide
201	 * @return {Object}
202	 */
203	args: function() {
204		var res = {}
205		for(var i=0; i < arguments.length; i++){
206			if(typeof arguments[i] == 'function'){
207				res.callback = arguments[i]
208			}else if(arguments[i] && arguments[i].jquery){
209				res.element = arguments[i][0];
210			}else if(arguments[i] && arguments[i].nodeName){
211				res.element = arguments[i];
212			}else if(res.options && typeof arguments[i] == 'string'){ //we can get by id
213				res.element = document.getElementById(arguments[i])
214			}
215			else if(arguments[i]){
216				res.options = arguments[i];
217			}
218		}
219		return res;
220	},
221	click: function( options, element, callback ) {
222		Syn('click!',options,element, callback);
223	},
224	/**
225	 * @attribute defaults
226	 * Default actions for events.  Each default function is called with this as its 
227	 * element.  It should return true if a timeout 
228	 * should happen after it.  If it returns an element, a timeout will happen
229	 * and the next event will happen on that element.
230	 */
231	defaults : {
232		focus: function() {
233			if(!Syn.support.focusChanges){
234				var element = this,
235					nodeName = element.nodeName.toLowerCase();
236				Syn.data(element,"syntheticvalue", element.value)
237				
238				//TODO, this should be textarea too
239				//and this might be for only text style inputs ... hmmmmm ....
240				
241				if(nodeName == "input" || nodeName == "textarea"){ 
242					bind(element, "blur", function(){
243						if( Syn.data(element,"syntheticvalue") !=  element.value){
244							
245							Syn.trigger("change", {}, element);
246						}
247						unbind(element,"blur", arguments.callee)
248					})
249					
250				}
251			}
252		},
253		submit: function() {
254			Syn.onParents(this, function(el){
255				if( el.nodeName.toLowerCase() == 'form'){
256					el.submit()
257					return false;
258				}
259			});
260		}
261	},
262	changeOnBlur: function( element, prop, value ) {
263		
264		bind(element, "blur", function(){		
265			if( value !=  element[prop]){
266				Syn.trigger("change", {}, element);
267			}
268			unbind(element,"blur", arguments.callee)
269		})
270		
271	},
272	/**
273	 * Returns the closest element of a particular type.
274	 * @hide
275	 * @param {Object} el
276	 * @param {Object} type
277	 */
278	closest: function( el, type ) {
279		while(el && el.nodeName.toLowerCase() != type.toLowerCase()){
280			el = el.parentNode
281		}
282		return el;
283	},
284	/**
285	 * adds jQuery like data (adds an expando) and data exists FOREVER :)
286	 * @hide
287	 * @param {Object} el
288	 * @param {Object} key
289	 * @param {Object} value
290	 */
291	data: function( el, key, value ) {
292		var d;
293		if(!el[expando]){
294			el[expando] = id++;
295		}
296		if(!data[el[expando]]){
297			data[el[expando]] = {};
298		}
299		d = data[el[expando]]
300		if(value){
301			data[el[expando]][key] = value;
302		}else{
303			return data[el[expando]][key];
304		}
305	},
306	/**
307	 * Calls a function on the element and all parents of the element until the function returns
308	 * false.
309	 * @hide
310	 * @param {Object} el
311	 * @param {Object} func
312	 */
313	onParents: function( el, func ) {
314		var res;
315		while(el && res !== false){
316			res = func(el)
317			el = el.parentNode
318		}
319		return el;
320	},
321	//regex to match focusable elements
322	focusable : /^(a|area|frame|iframe|label|input|select|textarea|button|html|object)$/i,
323	/**
324	 * Returns if an element is focusable
325	 * @hide
326	 * @param {Object} elem
327	 */
328	isFocusable: function( elem ) {
329		var attributeNode;
330		return ( this.focusable.test(elem.nodeName) || (
331			(attributeNode = elem.getAttributeNode( "tabIndex" )) && attributeNode.specified ) )
332			&& Syn.isVisible(elem)
333	},
334	/**
335	 * Returns if an element is visible or not
336	 * @hide
337	 * @param {Object} elem
338	 */
339	isVisible: function( elem ) {
340		return (elem.offsetWidth && elem.offsetHeight) || (elem.clientWidth && elem.clientHeight)
341	},
342	/**
343	 * Gets the tabIndex as a number or null
344	 * @hide
345	 * @param {Object} elem
346	 */
347	tabIndex: function( elem ) {
348		var attributeNode = elem.getAttributeNode( "tabIndex" );
349		return attributeNode && attributeNode.specified && ( parseInt( elem.getAttribute('tabIndex') ) || 0 )
350	},
351	bind : bind,
352	unbind : unbind,
353	browser: browser,
354	//some generic helpers
355	helpers : {
356		createEventObject : createEventObject,
357		createBasicStandardEvent: function( type, defaults , doc) {
358			var event;
359			try {
360				event = doc.createEvent("Events");
361			} catch(e2) {
362				event = doc.createEvent("UIEvents");
363			} finally {
364				event.initEvent(type, true, true);
365				extend(event, defaults);
366			}
367			return event;
368		},
369		inArray: function( item, array ) {
370			for(var i =0; i < array.length; i++){
371				if(array[i] == item){
372					return i;
373				}
374			}
375			return -1;
376		},
377		getWindow: function( element ) {
378			return element.ownerDocument.defaultView || element.ownerDocument.parentWindow
379		},
380		extend:  extend,
381		scrollOffset: function( win ) {
382			var doc = win.document.documentElement,
383				body = win.document.body;
384			return {
385				left :  (doc && doc.scrollLeft || body && body.scrollLeft || 0) + (doc.clientLeft || 0),
386				top : (doc && doc.scrollTop || body && body.scrollTop || 0) + (doc.clientTop || 0)
387			}
388				
389		},
390		addOffset: function( options, el ) {
391			var jq = Syn.jquery(el)
392			if(typeof options == 'object' &&
393			   options.clientX === undefined &&
394			   options.clientY === undefined &&
395			   options.pageX   === undefined &&
396			   options.pageY   === undefined && jq){
397				var el = jq(el)
398					off = el.offset();
399				options.pageX = off.left + el.width() /2 ;
400				options.pageY = off.top + el.height() /2 ;
401			}
402		}
403	},
404	// place for key data
405	key : {
406		ctrlKey : null,
407		altKey : null,
408		shiftKey : null,
409		metaKey : null
410	},
411	//triggers an event on an element, returns true if default events should be run
412	/**
413	 * Dispatches an event and returns true if default events should be run.
414	 * @hide
415	 * @param {Object} event
416	 * @param {Object} element
417	 * @param {Object} type
418	 * @param {Object} autoPrevent
419	 */
420	dispatch : function(event, element, type, autoPrevent){
421		
422		// dispatchEvent doesn't always work in IE (mostly in a popup)
423		if(element.dispatchEvent){	
424			var preventDefault = event.preventDefault, 
425				prevents = autoPrevent ? -1 : 0;
426			
427			//automatically prevents the default behavior for this event
428			//this is to protect agianst nasty browser freezing bug in safari
429			if(autoPrevent){
430				bind(element, type, function(ev){
431					ev.preventDefault()
432					unbind(this, type, arguments.callee)
433				})
434			}
435			
436			
437			event.preventDefault = function(){
438				prevents++;
439				if(++prevents > 0){
440					preventDefault.apply(this,[]);
441				}
442			}
443			element.dispatchEvent(event)
444			return prevents <= 0;
445		} else {
446			try {window.event = event;}catch(e) {}
447			//source element makes sure element is still in the document
448			return element.sourceIndex <= 0 || element.fireEvent('on'+type, event)
449		}
450	},
451	/**
452	 * @attribute
453	 * @hide
454	 * An object of eventType -> function that create that event.
455	 */
456	create :  {
457		//-------- PAGE EVENTS ---------------------
458		page : {
459			event: function(type, options, element){
460				if (Syn.helpers.getWindow(element).document.createEvent) {
461					var event = element.ownerDocument.createEvent("Events");
462					event.initEvent(type, true, true);
463					return event;
464				}
465				else {
466					return createEventObject(type, options, element);
467				}
468			}
469		},
470		// unique events
471		focus : {
472			event: function( type, options, element ) {
473				Syn.onParents(element, function(el){
474					if( Syn.isFocusable(el)){
475						if(el.nodeName.toLowerCase() != 'html'){
476							el.focus();
477							activeElement = el;
478						}
479						else if(activeElement){
480							// TODO: The HTML element isn't focasable in IE, but it is
481							// in FF.  We should detect this and do a true focus instead
482							// of just a blur
483							var doc = Syn.helpers.getWindow(element).document;
484							if(doc != window.document){
485								return false;
486							}else if(doc.activeElement){
487								doc.activeElement.blur();
488								activeElement = null;
489							}else{
490								activeElement.blur();
491								activeElement = null;
492							}
493							
494							
495						}
496						return false
497					}
498				});
499				return true;
500			}
501		}
502	},
503	/**
504	 * @attribute support
505	 * Feature detected properties of a browser's event system.
506	 * Support has the following properties:
507	 * <ul>
508	 * 	<li><code>clickChanges</code> - clicking on an option element creates a change event.</li>
509	 *  <li><code>clickSubmits</code> - clicking on a form button submits the form.</li>
510	 *  <li><code>mouseupSubmits</code> - a mouseup on a form button submits the form.</li>
511	 *  <li><code>radioClickChanges</code> - clicking a radio button changes the radio.</li>
512	 *  <li><code>focusChanges</code> - focus/blur creates a change event.</li>
513	 *  <li><code>linkHrefJS</code> - An achor's href JavaScript is run.</li>
514	 *  <li><code>mouseDownUpClicks</code> - A mousedown followed by mouseup creates a click event.</li>
515	 *  <li><code>tabKeyTabs</code> - A tab key changes tabs.</li>
516	 *  <li><code>keypressOnAnchorClicks</code> - Keying enter on an anchor triggers a click.</li>
517	 * </ul>
518	 */
519	support : {
520		clickChanges : false,
521		clickSubmits : false,
522		keypressSubmits : false,
523		mouseupSubmits: false,
524		radioClickChanges : false,
525		focusChanges : false,
526		linkHrefJS : false,
527		keyCharacters : false,
528		backspaceWorks : false,
529		mouseDownUpClicks : false,
530		tabKeyTabs : false,
531		keypressOnAnchorClicks : false,
532		optionClickBubbles : false,
533		ready : 0
534	},
535	/**
536	 * Creates a synthetic event and dispatches it on the element.  
537	 * This will run any default actions for the element.
538	 * Typically you want to use Syn, but if you want the return value, use this.
539	 * @param {String} type
540	 * @param {Object} options
541	 * @param {HTMLElement} element
542	 * @return {Boolean} true if default events were run, false if otherwise.
543	 */
544	trigger: function( type, options, element ) {
545		options || (options = {});
546		
547		var create = Syn.create,
548			setup = create[type] && create[type].setup,
549			kind = key.test(type) ? 
550				'key' : 
551				( page.test(type) ?
552					"page" : "mouse" ),
553				createType = create[type] || {},
554				createKind = create[kind],
555				event,
556				ret,
557				autoPrevent,
558				dispatchEl = element;
559		
560		//any setup code?
561		Syn.support.ready == 2 && setup && setup(type, options, element);
562		
563		autoPrevent = options._autoPrevent;
564		//get kind
565		
566		delete options._autoPrevent;
567			
568		if(createType.event){
569			ret = createType.event(type, options, element)
570		}else{
571			//convert options
572			options = createKind.options ? createKind.options(type,options,element) : options;
573			
574			if(!Syn.support.changeBubbles && /option/i.test(element.nodeName)){
575				dispatchEl = element.parentNode; //jQuery expects clicks on select
576			}
577			
578			//create the event
579			event = createKind.event(type,options,dispatchEl)
580			
581			//send the event
582			ret = Syn.dispatch(event, dispatchEl, type, autoPrevent)
583		}
584		
585		//run default behavior
586		ret && Syn.support.ready == 2
587			&& Syn.defaults[type] 
588			&& Syn.defaults[type].call(element, options, autoPrevent);
589		return ret;
590	},
591	eventSupported: function( eventName ) { 
592		var el = document.createElement("div"); 
593		eventName = "on" + eventName; 
594
595		var isSupported = (eventName in el); 
596		if ( !isSupported ) { 
597			el.setAttribute(eventName, "return;"); 
598			isSupported = typeof el[eventName] === "function"; 
599		} 
600		el = null; 
601
602		return isSupported; 
603	}
604	
605});
606	var h = Syn.helpers;
607/**
608 * @Prototype
609 */
610extend(Syn.init.prototype,{
611	/**
612	 * @function then
613	 * <p>
614	 * Then is used to chain a sequence of actions to be run one after the other.
615	 * This is useful when many asynchronous actions need to be performed before some
616	 * final check needs to be made.
617	 * </p>
618	 * <p>The following clicks and types into the <code>id='age'</code> element and then checks that only numeric characters can be entered.</p>
619	 * <h3>Example</h3>
620	 * @codestart
621	 * Syn('click',{},'age')
622	 *   .then('type','I am 12',function(){
623	 *   equals($('#age').val(),"12")  
624	 * })
625	 * @codeend
626	 * If the element argument is undefined, then the last element is used.
627	 * 
628	 * @param {String} type The type of event or action to create: "_click", "_dblclick", "_drag", "_type".
629	 * @param {Object} options Optiosn to pass to the event.
630	 * @param {String|HTMLElement} [element] A element's id or an element.  If undefined, defaults to the previous element.
631	 * @param {Function} [callback] A function to callback after the action has run, but before any future chained actions are run.
632	 */
633	then: function( type, options, element, callback ) {
634		if(Syn.autoDelay){
635			this.delay();
636		}
637		var args = Syn.args(options,element, callback),
638			self = this;
639
640		
641		//if stack is empty run right away
642		
643		//otherwise ... unshift it
644		this.queue.unshift(function(el, prevented){
645			
646			if(typeof this[type] == "function") {
647				this.element = args.element || el;
648				this[type](args.options, this.element, function(defaults, el){
649					args.callback && args.callback.apply(self, arguments);
650					self.done.apply(self, arguments)		
651				})
652			}else{
653				this.result = Syn.trigger(type, args.options, args.element);
654				args.callback && args.callback.call(this, args.element, this.result);
655				return this;
656			}
657		})
658		return this;
659	},
660	/**
661	 * Delays the next command a set timeout.
662	 * @param {Number} [timeout]
663	 * @param {Function} [callback]
664	 */
665	delay: function( timeout, callback ) {
666		if(typeof timeout == 'function'){
667			callback = timeout;
668			timeout = null;
669		}
670		timeout = timeout || 600
671		var self = this;
672		this.queue.unshift(function(){
673			setTimeout(function(){
674				callback && callback.apply(self,[])
675				self.done.apply(self, arguments)
676			},timeout)
677		})
678		return this;
679	},
680	done: function( defaults, el ) {
681		el && (this.element = el);;
682		if(this.queue.length){
683			this.queue.pop().call(this, this.element, defaults);
684		}
685		
686	},
687	/**
688	 * @function click
689	 * Clicks an element by triggering a mousedown, 
690	 * mouseup, 
691	 * and a click event.
692	 * <h3>Example</h3>
693	 * @codestart
694	 * Syn.click({},'create',function(){
695	 *   //check something
696	 * })
697	 * @codeend
698	 * You can also provide the coordinates of the click.  
699	 * If jQuery is present, it will set clientX and clientY
700	 * for you.  Here's how to set it yourself:
701	 * @codestart
702	 * Syn.click(
703	 *     {clientX: 20, clientY: 100},
704	 *     'create',
705	 *     function(){
706	 *       //check something
707	 *     })
708	 * @codeend
709	 * You can also provide pageX and pageY and Syn will convert it for you.
710	 * @param {Object} options
711	 * @param {HTMLElement} element
712	 * @param {Function} callback
713	 */
714	"_click" : function( options, element, callback, force ) {
715		Syn.helpers.addOffset(options, element);
716		Syn.trigger("mousedown", options, element);
717		
718		//timeout is b/c IE is stupid and won't call focus handlers
719		setTimeout(function(){
720			Syn.trigger("mouseup", options, element)
721			if(!Syn.support.mouseDownUpClicks || force){
722				Syn.trigger("click", options, element)
723				callback(true)
724			}else{
725				//we still have to run the default (presumably)
726				Syn.create.click.setup('click',options,element)
727				Syn.defaults.click.call(element)
728				//must give time for callback
729				setTimeout(function(){
730					callback(true)
731				},1)
732			}
733			
734		},1)
735	},
736	/**
737	 * Right clicks in browsers that support it (everyone but opera).
738	 * @param {Object} options
739	 * @param {Object} element
740	 * @param {Object} callback
741	 */
742	"_rightClick" : function( options, element, callback ) {
743		Syn.helpers.addOffset(options, element);
744		var mouseopts =  extend( extend({},Syn.mouse.browser.right.mouseup ), options)
745		
746		Syn.trigger("mousedown", mouseopts, element);
747		
748		//timeout is b/c IE is stupid and won't call focus handlers
749		setTimeout(function(){
750			Syn.trigger("mouseup", mouseopts, element)
751			if (Syn.mouse.browser.contextmenu) {
752				Syn.trigger("contextmenu", 
753					extend( extend({},Syn.mouse.browser.right.contextmenu ), options), 
754					element)
755			}
756			callback(true)
757		},1)
758	},
759	/**
760	 * @function dblclick
761	 * Dblclicks an element.  This runs two [Syn.prototype.click click] events followed by
762	 * a dblclick on the element.
763	 * <h3>Example</h3>
764	 * @codestart
765	 * Syn.dblclick({},'open')
766	 * @codeend
767	 * @param {Object} options
768	 * @param {HTMLElement} element
769	 * @param {Function} callback
770	 */
771	"_dblclick" : function( options, element, callback ) {
772		Syn.helpers.addOffset(options, element);
773		var self = this;
774		this._click(options, element, function(){
775			setTimeout(function(){
776				self._click(options, element, function(){
777					Syn.trigger("dblclick", options, element)
778					callback(true)
779				},true)
780			},2)
781			
782		})
783	}
784})
785
786var actions = ["click","dblclick","move","drag","key","type",'rightClick'],
787	makeAction = function(name){
788		Syn[name] = function(options, element, callback){
789			return Syn("_"+name, options, element, callback)
790		}
791		Syn.init.prototype[name] = function(options, element, callback){
792			return this.then("_"+name, options, element, callback)
793		}
794	}
795for(var i=0; i < actions.length; i++){
796	makeAction(actions[i]);
797}
798/**
799 * Used for creating and dispatching synthetic events.
800 * @codestart
801 * new MVC.Syn('click').send(MVC.$E('id'))
802 * @codeend
803 * @constructor Sets up a synthetic event.
804 * @param {String} type type of event, ex: 'click'
805 * @param {optional:Object} options
806 */
807if (window.jQuery || (window.FuncUnit && window.FuncUnit.jquery)) {
808	((window.FuncUnit && window.FuncUnit.jquery) || window.jQuery  ).fn.triggerSyn = function(type, options, callback){
809		Syn(type, options, this[0], callback)
810		return this;
811	};
812}
813
814window.Syn = Syn;
815}())