| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define(function(require){ var module = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var keyboard = require('../keyboard') | 
					
						
							| 
									
										
										
										
											2015-12-08 07:42:07 +03:00
										 |  |  | var object = require('../object') | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | var widget = require('./widget') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 22:07:31 +03:00
										 |  |  | var DrawerClassPrototype = { | 
					
						
							| 
									
										
										
										
											2015-11-09 22:48:13 +03:00
										 |  |  | 	make: function(obj, client, options){ | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 		var that = this | 
					
						
							|  |  |  | 		var overlay = $('<div>') | 
					
						
							|  |  |  | 			.addClass('drawer-widget') | 
					
						
							|  |  |  | 			.on(options.nonPropagatedEvents.join(' '), function(){ | 
					
						
							|  |  |  | 				event.stopPropagation() | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.append($('<div>') | 
					
						
							|  |  |  | 				.addClass('content') | 
					
						
							|  |  |  | 				.click(function(){ | 
					
						
							|  |  |  | 					event.stopPropagation() | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				.append(client)) | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if(options.focusable){ | 
					
						
							|  |  |  | 			overlay.attr('tabindex', 0) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 22:48:13 +03:00
										 |  |  | 		// XXX make this part of the framework...
 | 
					
						
							|  |  |  | 		if(obj){ | 
					
						
							|  |  |  | 			overlay.data('widget-controller', obj) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 		return overlay | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 22:07:31 +03:00
										 |  |  | var DrawerPrototype = { | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 	dom: null, | 
					
						
							|  |  |  | 	client: null, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	options: { | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 		focusable: false, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-22 22:50:18 +03:00
										 |  |  | 		'close-at': 40, | 
					
						
							| 
									
										
										
										
											2015-09-18 22:02:45 +03:00
										 |  |  | 		'fade-at': 100, | 
					
						
							|  |  |  | 		'animate': 120, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 		nonPropagatedEvents: [ | 
					
						
							|  |  |  | 			'click', | 
					
						
							|  |  |  | 			'keydown', | 
					
						
							|  |  |  | 		], | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	keyboard: { | 
					
						
							|  |  |  | 		General: { | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 			//pattern: '.drawer-widget',
 | 
					
						
							|  |  |  | 			pattern: '*', | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			Esc: 'close', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// custom events...
 | 
					
						
							|  |  |  | 	close: function(handler){ | 
					
						
							|  |  |  | 		// trigger the event...
 | 
					
						
							|  |  |  | 		if(handler == null){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 			this.dom.animate({ | 
					
						
							|  |  |  | 					scrollTop: 0, | 
					
						
							|  |  |  | 					opacity: 0, | 
					
						
							|  |  |  | 					filter: 'none', | 
					
						
							|  |  |  | 				},  | 
					
						
							| 
									
										
										
										
											2015-09-18 22:02:45 +03:00
										 |  |  | 				this.options['animate'], | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 				function(){ | 
					
						
							|  |  |  | 					that.dom.detach() | 
					
						
							|  |  |  | 					if(that.parent.children('.overlay-widget').length == 0){ | 
					
						
							|  |  |  | 						that.parent.removeClass('blur') | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					that.trigger('close') | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// register a handler...
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.on('close', handler) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 		return this | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	__init__: function(parent, client, options){ | 
					
						
							|  |  |  | 		var that = this | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 		object.superMethod(Drawer, '__init__').call(this, parent, client, options) | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 		var client_dom = client.dom || client | 
					
						
							|  |  |  | 		var dom = this.dom | 
					
						
							|  |  |  | 		options = this.options | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 		this.parent | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 			.addClass('blur') | 
					
						
							|  |  |  | 			.append(dom) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// add keyboard handler...
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | 		dom | 
					
						
							|  |  |  | 			.click(function(){ | 
					
						
							|  |  |  | 				that.close() | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 			.css({opacity: 0}) | 
					
						
							|  |  |  | 			.animate({ | 
					
						
							|  |  |  | 					scrollTop: Math.min( | 
					
						
							|  |  |  | 						client_dom.outerHeight(),  | 
					
						
							|  |  |  | 						// do not scroll more than the container height and
 | 
					
						
							|  |  |  | 						// keep a bit on top...
 | 
					
						
							| 
									
										
										
										
											2015-09-18 22:02:45 +03:00
										 |  |  | 						(parent.is('body') ? $(document) : parent) | 
					
						
							|  |  |  | 							.outerHeight()-options['fade-at'])+'px', | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 					opacity: 1, | 
					
						
							|  |  |  | 				},  | 
					
						
							| 
									
										
										
										
											2015-09-18 22:02:45 +03:00
										 |  |  | 				options['animate'], | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 				function(){ | 
					
						
							|  |  |  | 					dom.scroll(function(){ | 
					
						
							|  |  |  | 						var st = $(this).scrollTop() | 
					
						
							| 
									
										
										
										
											2015-09-18 22:02:45 +03:00
										 |  |  | 						var h = Math.min(options['fade-at'], client_dom.outerHeight()) | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 						// start fading...
 | 
					
						
							|  |  |  | 						if(st < h){ | 
					
						
							|  |  |  | 							dom.css({ opacity: Math.min(1, st/h) }) | 
					
						
							|  |  |  | 						} else if(dom.css('opacity') < 1){ | 
					
						
							|  |  |  | 							dom.css('opacity', 1) | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						// close drawer when scrolling to the top...
 | 
					
						
							| 
									
										
										
										
											2015-09-18 22:02:45 +03:00
										 |  |  | 						if(st < options['close-at']){ | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 							that.close() | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// focus the client...
 | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 		if(client.dom && client.focus){ | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 			client.focus() | 
					
						
							| 
									
										
										
										
											2015-09-22 23:55:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.focus() | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return this | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 22:07:31 +03:00
										 |  |  | var Drawer =  | 
					
						
							|  |  |  | module.Drawer =  | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | object.makeConstructor('Drawer',  | 
					
						
							| 
									
										
										
										
											2015-09-18 22:07:31 +03:00
										 |  |  | 		DrawerClassPrototype,  | 
					
						
							|  |  |  | 		DrawerPrototype) | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-20 21:54:28 +03:00
										 |  |  | // inherit from widget...
 | 
					
						
							|  |  |  | Drawer.prototype.__proto__ = widget.Container.prototype | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							|  |  |  | return module }) |