| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 04:34:26 +04:00
										 |  |  | function makePanel(title, open, editable_title, keep_empty){ | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 	title = title == null ? ' ' : title | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// tool panel...
 | 
					
						
							|  |  |  | 	var panel = $('<details/>') | 
					
						
							|  |  |  | 		.prop('open', open == null ? true : open) | 
					
						
							|  |  |  | 		.addClass('panel noScroll') | 
					
						
							|  |  |  | 		.append($('<summary>'+title+'</summary>') | 
					
						
							|  |  |  | 			.attr({ | 
					
						
							|  |  |  | 				contenteditable: editable_title == null ? 'false' : 'true', | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 			.append($('<span/>') | 
					
						
							|  |  |  | 				.addClass('close-button') | 
					
						
							|  |  |  | 				.click(function(){ | 
					
						
							|  |  |  | 					panel | 
					
						
							|  |  |  | 						.trigger('panelClosing') | 
					
						
							| 
									
										
										
										
											2013-12-11 03:21:44 +04:00
										 |  |  | 						.remove() | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 					return false | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				.html('×'))) | 
					
						
							|  |  |  | 		.draggable({ | 
					
						
							|  |  |  | 			containment: 'parent', | 
					
						
							|  |  |  | 			scroll: false, | 
					
						
							|  |  |  | 			// XXX this makes things quite a bit slower...
 | 
					
						
							|  |  |  | 			stack: '.panel', | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 			//snap: ".panel", 
 | 
					
						
							|  |  |  | 			//snapMode: "outer",
 | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.css({ | 
					
						
							|  |  |  | 			// for some reason this is overwritten by jquery-ui to 'relative'...
 | 
					
						
							|  |  |  | 			//position: '',
 | 
					
						
							|  |  |  | 			position: 'absolute', | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// wrapper for sub-panels...
 | 
					
						
							| 
									
										
										
										
											2013-12-23 03:57:18 +04:00
										 |  |  | 	// XXX dragging out, into another panel and back out behaves oddly:
 | 
					
						
							|  |  |  | 	// 		should:
 | 
					
						
							|  |  |  | 	// 			either revert or create a new panel
 | 
					
						
							|  |  |  | 	// 		does:
 | 
					
						
							|  |  |  | 	// 			drops to last placeholder
 | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 	var content = $('<span class="panel-content content">') | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 		.sortable({ | 
					
						
							|  |  |  | 			forcePlaceholderSize: true, | 
					
						
							|  |  |  | 			opacity: 0.7, | 
					
						
							|  |  |  | 			connectWith: '.panel-content', | 
					
						
							| 
									
										
										
										
											2013-12-23 03:43:21 +04:00
										 |  |  | 			zIndex: 9999, | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			start: function(e, ui){ | 
					
						
							| 
									
										
										
										
											2013-12-23 03:57:18 +04:00
										 |  |  | 				//console.log('start')
 | 
					
						
							| 
									
										
										
										
											2013-12-12 04:34:26 +04:00
										 |  |  | 				ui.item.data('isoutside', false) | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 				ui.placeholder.height(ui.helper.outerHeight()); | 
					
						
							|  |  |  | 				ui.placeholder.width(ui.helper.outerWidth()); | 
					
						
							| 
									
										
										
										
											2013-12-23 04:38:49 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			// create a new panel when dropping outside of curent panel...
 | 
					
						
							| 
									
										
										
										
											2013-12-12 04:34:26 +04:00
										 |  |  | 			beforeStop: function(e, ui){ | 
					
						
							| 
									
										
										
										
											2013-12-23 03:57:18 +04:00
										 |  |  | 				//console.log('stop')
 | 
					
						
							| 
									
										
										
										
											2013-12-23 03:43:21 +04:00
										 |  |  | 				var c = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 				// do this only when dropping outside the panel...
 | 
					
						
							| 
									
										
										
										
											2013-12-23 03:43:21 +04:00
										 |  |  | 				if(ui.item.data('isoutside') | 
					
						
							|  |  |  | 						// prevent draggingout the last panel...
 | 
					
						
							|  |  |  | 						// NOTE: 2 because we are taking into account 
 | 
					
						
							|  |  |  | 						// 		the placeholders...
 | 
					
						
							|  |  |  | 						&& panel.find('.sub-panel').length > 2){ | 
					
						
							|  |  |  | 					c = 1 | 
					
						
							|  |  |  | 					// compensate for removed item which is still in the
 | 
					
						
							|  |  |  | 					// panel when we count it...
 | 
					
						
							|  |  |  | 					// ...this is likely to the fact that we jquery-ui did
 | 
					
						
							|  |  |  | 					// not cleanup yet
 | 
					
						
							| 
									
										
										
										
											2013-12-11 03:21:44 +04:00
										 |  |  | 					var new_panel = makePanel() | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 						.css(ui.offset) | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 						.appendTo(panel.parent()) | 
					
						
							| 
									
										
										
										
											2013-12-11 03:21:44 +04:00
										 |  |  | 					new_panel.find('.panel-content') | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 							.append(ui.item) | 
					
						
							| 
									
										
										
										
											2013-12-11 03:21:44 +04:00
										 |  |  | 					panel.trigger('newPanel', [new_panel]) | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// remove the panel when it runs out of sub-panels...
 | 
					
						
							| 
									
										
										
										
											2013-12-23 03:43:21 +04:00
										 |  |  | 				if(!keep_empty && panel.find('.sub-panel').length-c <= 0){ | 
					
						
							| 
									
										
										
										
											2013-12-11 03:21:44 +04:00
										 |  |  | 					panel | 
					
						
							|  |  |  | 						.trigger('panelClosing') | 
					
						
							|  |  |  | 						.remove() | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-12-12 04:34:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				ui.item.data('isoutside', false) | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 			over: function(e, ui){ | 
					
						
							| 
									
										
										
										
											2013-12-23 03:57:18 +04:00
										 |  |  | 				//console.log('over')
 | 
					
						
							| 
									
										
										
										
											2013-12-12 04:34:26 +04:00
										 |  |  | 				ui.item.data('isoutside', false) | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			out: function(e, ui){ | 
					
						
							| 
									
										
										
										
											2013-12-23 03:57:18 +04:00
										 |  |  | 				//console.log('out')
 | 
					
						
							| 
									
										
										
										
											2013-12-12 04:34:26 +04:00
										 |  |  | 				ui.item.data('isoutside', true) | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.appendTo(panel) | 
					
						
							|  |  |  | 	return panel | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function makeSubPanel(title, open, parent){ | 
					
						
							|  |  |  | 	title = title == null ? ' ' : title | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var sub_panel = $('<details/>') | 
					
						
							|  |  |  | 		.addClass('sub-panel noScroll') | 
					
						
							|  |  |  | 		.prop('open', open == null ? true : open) | 
					
						
							|  |  |  | 		.append($('<summary>'+title+'</summary>')) | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 		.append($('<div class="sub-panel-content content"/>')) | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(parent != null){ | 
					
						
							|  |  |  | 		if(parent.hasClass('panel-content')){ | 
					
						
							|  |  |  | 			sub_panel.appendTo(parent) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			sub_panel.appendTo(parent.find('.panel-content')) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return sub_panel | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-23 04:38:49 +04:00
										 |  |  | // side can be:
 | 
					
						
							|  |  |  | // 	- left
 | 
					
						
							|  |  |  | // 	- right
 | 
					
						
							|  |  |  | function makeSidePanel(side){ | 
					
						
							|  |  |  | 	var panel = $('<div/>') | 
					
						
							|  |  |  | 		.addClass('side-panel panel-content ' + side) | 
					
						
							|  |  |  | 		.sortable({ | 
					
						
							|  |  |  | 			forcePlaceholderSize: true, | 
					
						
							|  |  |  | 			opacity: 0.7, | 
					
						
							|  |  |  | 			connectWith: '.panel-content', | 
					
						
							|  |  |  | 			zIndex: 9999, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			start: function(e, ui){ | 
					
						
							|  |  |  | 				//console.log('start')
 | 
					
						
							|  |  |  | 				ui.item.data('isoutside', false) | 
					
						
							|  |  |  | 				ui.placeholder.height(ui.helper.outerHeight()); | 
					
						
							|  |  |  | 				ui.placeholder.width(ui.helper.outerWidth()); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			// create a new panel when dropping outside of curent panel...
 | 
					
						
							|  |  |  | 			beforeStop: function(e, ui){ | 
					
						
							|  |  |  | 				//console.log('stop')
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// do this only when dropping outside the panel...
 | 
					
						
							|  |  |  | 				if(ui.item.data('isoutside')){ | 
					
						
							|  |  |  | 					// compensate for removed item which is still in the
 | 
					
						
							|  |  |  | 					// panel when we count it...
 | 
					
						
							|  |  |  | 					// ...this is likely to the fact that we jquery-ui did
 | 
					
						
							|  |  |  | 					// not cleanup yet
 | 
					
						
							|  |  |  | 					var new_panel = makePanel() | 
					
						
							|  |  |  | 						.css(ui.offset) | 
					
						
							|  |  |  | 						.appendTo(panel.parent()) | 
					
						
							|  |  |  | 					new_panel.find('.panel-content') | 
					
						
							|  |  |  | 							.append(ui.item) | 
					
						
							|  |  |  | 					panel.trigger('newPanel', [new_panel]) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				ui.item.data('isoutside', false) | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			over: function(e, ui){ | 
					
						
							|  |  |  | 				//console.log('over')
 | 
					
						
							|  |  |  | 				ui.item.data('isoutside', false) | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			out: function(e, ui){ | 
					
						
							|  |  |  | 				//console.log('out')
 | 
					
						
							|  |  |  | 				ui.item.data('isoutside', true) | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	return panel | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-09 21:10:12 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ |