| 
									
										
										
										
											2015-09-18 21:51:05 +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-18 21:51:05 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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>') | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 			.addClass('drawer-widget modal-widget ' + (options.direction || 'bottom')) | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 			.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
										 |  |  | 
 | 
					
						
							|  |  |  | 		return overlay | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 14:30:35 +03:00
										 |  |  | // XXX add a non-modal version...
 | 
					
						
							| 
									
										
										
										
											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', | 
					
						
							| 
									
										
										
										
											2016-04-30 20:14:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			'close', | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 		], | 
					
						
							| 
									
										
										
										
											2016-04-30 18:39:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		background: null, | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		direction: 'bottom', | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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({ | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 					scrollTop: this.options.direction == 'top'?  | 
					
						
							|  |  |  | 							this.dom.find('.content')[0].scrollHeight | 
					
						
							|  |  |  | 						: 0,  | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 					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() | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 			.css({ opacity: 0 }) | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 			.scrollTop(options.direction == 'top' ? | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 					dom.find('.content')[0].scrollHeight | 
					
						
							|  |  |  | 				: 0) | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 			.animate({ | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 					scrollTop:  | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 						(options.direction == 'top' ? | 
					
						
							|  |  |  | 							(dom.find('.content')[0].scrollHeight | 
					
						
							|  |  |  | 							 	- dom.outerHeight() | 
					
						
							|  |  |  | 								+ options['fade-at']) + 'px' | 
					
						
							|  |  |  | 						: Math.min( | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 								client_dom.outerHeight(),  | 
					
						
							|  |  |  | 								// do not scroll more than the container height and
 | 
					
						
							|  |  |  | 								// keep a bit on top...
 | 
					
						
							|  |  |  | 								(parent.is('body') ? $(document) : parent) | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 									.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() | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 						// top drawer...
 | 
					
						
							|  |  |  | 						if(options.direction == 'top'){ | 
					
						
							|  |  |  | 							var h = dom.find('.content')[0].scrollHeight | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							// start fading...
 | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 							if(st > h - options['fade-at']){ | 
					
						
							|  |  |  | 								dom.css({ opacity: Math.min(1, (h - st)/options['fade-at']) }) | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							} else if(dom.css('opacity') < 1){ | 
					
						
							|  |  |  | 								dom.css('opacity', 1) | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 							// close...
 | 
					
						
							|  |  |  | 							if(st > h - options['close-at']){ | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 								that.close() | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 						// bottom drawer...
 | 
					
						
							|  |  |  | 						} else if(options.direction == 'bottom'){ | 
					
						
							|  |  |  | 							var h = Math.min(options['fade-at'], client_dom.outerHeight()) | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							// start fading...
 | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 							if(st < h){ | 
					
						
							|  |  |  | 								dom.css({ opacity: Math.min(1, st/h) }) | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							} else if(dom.css('opacity') < 1){ | 
					
						
							|  |  |  | 								dom.css('opacity', 1) | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 							// close drawer when scrolling to the top...
 | 
					
						
							|  |  |  | 							if(st < options['close-at']){ | 
					
						
							| 
									
										
										
										
											2016-05-07 16:15:18 +03:00
										 |  |  | 								that.close() | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 18:39:14 +03:00
										 |  |  | 		if(options.background){ | 
					
						
							|  |  |  | 			dom.find('.content').css('background', options.background) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 21:51:05 +03:00
										 |  |  | 		// 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
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |