| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | var keyboard = require('../keyboard') | 
					
						
							| 
									
										
										
										
											2015-12-08 07:42:07 +03:00
										 |  |  | var object = require('../object') | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | var widget = require('./widget') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var OverlayClassPrototype = { | 
					
						
							| 
									
										
										
										
											2015-11-09 22:48:13 +03:00
										 |  |  | 	make: function(obj, client, options){ | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 		var that = this | 
					
						
							|  |  |  | 		var overlay = $('<div>') | 
					
						
							| 
									
										
										
										
											2016-05-08 14:30:35 +03:00
										 |  |  | 			.addClass('overlay-widget modal-widget') | 
					
						
							| 
									
										
										
										
											2018-03-19 01:42:36 +03:00
										 |  |  | 			.on(options.nonPropagatedEvents.join(' '), function(evt){ | 
					
						
							|  |  |  | 				evt = window.event || evt | 
					
						
							|  |  |  | 				evt.stopPropagation() | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2018-03-19 01:42:36 +03:00
										 |  |  | 			.on('contextmenu', function(evt){ | 
					
						
							|  |  |  | 				evt = window.event || evt | 
					
						
							|  |  |  | 				evt.preventDefault() | 
					
						
							|  |  |  | 				evt.stopPropagation() | 
					
						
							| 
									
										
										
										
											2016-03-05 02:45:02 +03:00
										 |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 			.append($('<div>') | 
					
						
							|  |  |  | 				.addClass('content') | 
					
						
							| 
									
										
										
										
											2018-03-19 01:42:36 +03:00
										 |  |  | 				.click(function(evt){ | 
					
						
							|  |  |  | 					evt = window.event || evt | 
					
						
							|  |  |  | 					evt.stopPropagation() | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2018-03-19 01:42:36 +03:00
										 |  |  | 				.on('contextmenu', function(evt){ | 
					
						
							|  |  |  | 					evt = window.event || evt | 
					
						
							|  |  |  | 					evt.preventDefault() | 
					
						
							|  |  |  | 					evt.stopPropagation() | 
					
						
							| 
									
										
										
										
											2016-03-05 02:15:11 +03:00
										 |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 				.append(client)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 		if(options.focusable){ | 
					
						
							|  |  |  | 			overlay.attr('tabindex', 0) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 		return overlay | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var OverlayPrototype = { | 
					
						
							|  |  |  | 	dom: null, | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 	client: null, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 01:01:06 +03:00
										 |  |  | 	options: { | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 		focusable: false, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 01:01:06 +03:00
										 |  |  | 		nonPropagatedEvents: [ | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 			'click', | 
					
						
							|  |  |  | 			'keydown', | 
					
						
							| 
									
										
										
										
											2015-09-08 01:01:06 +03:00
										 |  |  | 		], | 
					
						
							| 
									
										
										
										
											2015-12-15 03:44:50 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		closeOnUnFocusedClick: false, | 
					
						
							| 
									
										
										
										
											2015-09-08 01:01:06 +03:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 	// XXX for some reason this does not work...
 | 
					
						
							| 
									
										
										
										
											2017-01-12 02:09:59 +03:00
										 |  |  | 	keybindings: { | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 		General: { | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 			//pattern: '.overlay-widget',
 | 
					
						
							|  |  |  | 			pattern: '*', | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 00:14:31 +03:00
										 |  |  | 			Esc: 'close: "reject"', | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 	__init__: function(parent, client, options){ | 
					
						
							|  |  |  | 		var that = this | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-24 21:50:37 +03:00
										 |  |  | 		object.parent(OverlayPrototype.__init__, this).call(this, parent, client, options) | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-15 03:44:50 +03:00
										 |  |  | 		// Prevent closing the overlay if clicked while blurred...
 | 
					
						
							|  |  |  | 		// i.e.
 | 
					
						
							|  |  |  | 		// 	1'st click -- focus window
 | 
					
						
							|  |  |  | 		// 	2'nd click -- close overlay
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// XXX HACK: need a better way to do this...
 | 
					
						
							| 
									
										
										
										
											2015-12-15 06:42:18 +03:00
										 |  |  | 		var focused = document.hasFocus() | 
					
						
							| 
									
										
										
										
											2015-12-15 03:44:50 +03:00
										 |  |  | 		var unlock = function() { setTimeout(function(){ focused = true }, 200) } | 
					
						
							|  |  |  | 		var lock = function() { focused = false } | 
					
						
							|  |  |  | 		// blur-lock...
 | 
					
						
							|  |  |  | 		$(window) | 
					
						
							|  |  |  | 			.focus(unlock) | 
					
						
							|  |  |  | 			.blur(lock) | 
					
						
							|  |  |  | 		// cleanup...
 | 
					
						
							|  |  |  | 		this.close(function(){ | 
					
						
							|  |  |  | 			$(window) | 
					
						
							|  |  |  | 				.off('focus', unlock) | 
					
						
							|  |  |  | 				.off('blur', lock) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 		this.dom | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 			.click(function(){ | 
					
						
							| 
									
										
										
										
											2015-12-15 03:44:50 +03:00
										 |  |  | 				if(that.options.closeOnUnFocusedClick || focused){ | 
					
						
							| 
									
										
										
										
											2017-01-24 00:14:31 +03:00
										 |  |  | 					that.close('reject') | 
					
						
							| 
									
										
										
										
											2015-12-15 03:44:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-05 18:11:57 +03:00
										 |  |  | 				// don't make the user wait if they really want to close...
 | 
					
						
							| 
									
										
										
										
											2015-12-15 03:44:50 +03:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					focused = true | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 			}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 		this.parent | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 			.addClass('blur') | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 			.append(this.dom) | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 05:17:14 +03:00
										 |  |  | 		this | 
					
						
							|  |  |  | 			// pass focus to the client if it is not focused already...
 | 
					
						
							|  |  |  | 			.on('focus click', function(){ | 
					
						
							|  |  |  | 				client.focus && client.focus() | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			// close...
 | 
					
						
							|  |  |  | 			.close(function(){ | 
					
						
							|  |  |  | 				that.dom.detach() | 
					
						
							|  |  |  | 				if(that.parent.children('.overlay-widget').length == 0){ | 
					
						
							|  |  |  | 					that.parent.removeClass('blur') | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-15 06:42:18 +03:00
										 |  |  | 		this.focus() | 
					
						
							| 
									
										
										
										
											2015-09-12 03:10:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | var Overlay =  | 
					
						
							|  |  |  | module.Overlay =  | 
					
						
							| 
									
										
										
										
											2019-07-17 00:07:24 +03:00
										 |  |  | object.Constructor('Overlay',  | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 		OverlayClassPrototype,  | 
					
						
							|  |  |  | 		OverlayPrototype) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | // inherit from widget...
 | 
					
						
							|  |  |  | Overlay.prototype.__proto__ = widget.Container.prototype | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:48:13 +03:00
										 |  |  | // XXX this should return a proxy with a set of extension API...
 | 
					
						
							|  |  |  | var getOverlay = | 
					
						
							|  |  |  | module.getOverlay = function(obj){ | 
					
						
							|  |  |  | 	var overlay = $(obj || 'body') | 
					
						
							|  |  |  | 		.find('.overlay-widget') | 
					
						
							|  |  |  | 		.last() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(overlay.length == 0){ | 
					
						
							|  |  |  | 		return null | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// get the controller...
 | 
					
						
							|  |  |  | 	return overlay.data('widget-controller') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 18:44:10 +03:00
										 |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |