Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2009, 10:50 PM
final kaoss final kaoss is offline
 
Join Date: Apr 2006
Posts: 1,314
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default No drag implementation

So I was browsing along today and found this:
http://www.codingforums.com/showthread.php?t=76715

Code:
// dragdropable.js (1.0.1)
//	Copyright (C) 2006 Jason Davis, www.jasonkarldavis.com
//	This code is licensed under the LGPL:
//		http://www.gnu.org/licenses/lgpl.html
//
// Documentation:
//	This script exposes two global variables, Draggable and Droppable. To make an
//	element draggable, simply call `Draggable(element)`. This sets the necessary
//	CSS properties and event handlers. It also overrides the addEventListener and
//	and attachEvent methods (if present) to include the following events:
//		onstart		(When the element begins dragging)
//		ondrag		(When the element is being dragged)
//		onstop		(When the element has stopped dragging)
//	You may also assign element.onstart, element.ondrag, and element.onstart to
//	add event listeners.
//	Lastly, if you need to physically prevent an element from dragging, you may
//	call event.preventDefault() from within the onstart handler.
//
//	To make an element droppable (have things dragged onto it), call
//	`Droppable(element)`. This sets the necessary event handlers and coordinate
//	searches. Once again, it overrides addEventListener and attachEvent to
//	include the following events:
//		onhover		(When another element has been dragged over the element)
//		ondrop		(When another element has been dropped onto the element)
//		onunhover	(When another element has been dragged off the element)
//	As before, you may also set element.onhover, element.ondrop, and
//	element.onunhover directly.
//	To remove all drop points from the current session, call `Droppable.reset()`.
//
//	The event object is also extended with the following properties:
//		dragTarget	(The element being dragged)
//		dropTarget	(The element being dropped onto)
//
// Known bugs:
//	* removeEventListener and detachEvent do not work with the custom events.
//		Workaround: Use direct assignment (element.onevent) instead.
//	* There is no way to remove a single drop point.
//		Workaround: Call Droppable.reset(), then reinitialize the other drop points.
//	* There is no way to remove dragging from an element.
//		Workaround: element.onstart = function(event) { event.preventDefault() }
//	* Changing position of droppable elements after initialization breaks drop
//		Workaround: Static droppables are much faster than moving ones. Either call
//		Droppable.reset() and reinitialize often, or ask the author to modify the
//		script to account for this (and accept the resulting slowdown)


function Draggable(element) {
	// initialize drag variable
	var x = 0, y = 0, oldMouseMove, oldMouseUp;

	// get style properties of element
	var computedStyle;
	if (typeof document.defaultView != "undefined" && typeof document.defaultView.getComputedStyle != "undefined")
		computedStyle = document.defaultView.getComputedStyle(element, "");
	else if (typeof element.currentStyle != "undefined")
		computedStyle = element.currentStyle;
	else
		computedStyle = element.style;

	// prep element for dragging
	if (computedStyle.position == "static" || computedStyle.position == "")
		element.style.position = "relative";
	if (computedStyle.zIndex == "auto" || computedStyle.zIndex == "")
		element.style.zIndex = 1;
	element.style.left = isNaN(parseInt(computedStyle.left)) ? "0" : computedStyle.left;
	element.style.top  = isNaN(parseInt(computedStyle.top )) ? "0" : computedStyle.top;

	// default event listeners
	function onstart(event) {
		event.dragTarget = element;
		x = event.clientX;
		y = event.clientY;

		// Override preventDefault
		event.preventDefault = (function(original) {
			return function() {
				element.ownerDocument.onmousemove = oldMouseMove;
				element.ownerDocument.onmouseup = oldMouseUp;
				original.call(event);
			}
		})(event.preventDefault || function() {});

		if (element.onstart) element.onstart(event);
	}
	function ondrag(event) {
		event.dragTarget = element;
		element.style.left = parseInt(element.style.left) + event.clientX - x + "px";
		element.style.top  = parseInt(element.style.top)  + event.clientY - y + "px";
		x = event.clientX;
		y = event.clientY;
		Droppable.query(event);
		
		if (element.ondrag) element.ondrag(event);
	}
	function onstop(event) {
		event.dragTarget = element;
		Droppable.query(event);
		
		if (element.onstop) element.onstop(event);
	}

	// make listeners active
	element.onmousedown = (function(oldMouseDown) {
		return function() {
			// Call old listener
			if (oldMouseDown) oldMouseDown.apply(this, arguments);

			// Store old event handlers
			oldMouseMove = this.ownerDocument.onmousemove;
			oldMouseUp   = this.ownerDocument.onmouseup;

			// Setup events
			this.ownerDocument.onmousemove = function() {
				// Call old listener
				if (oldMouseMove) oldMouseMove.apply(this, arguments);

				// Call ondrag
				ondrag.call(element, arguments[0] || event);

				return false;
			}
			this.ownerDocument.onmouseup = function() {
				// Call old listener
				if (oldMouseUp) oldMouseUp.apply(this, arguments);

				// Call onstop
				onstop.call(element, arguments[0] || event);

				// Restore old event listeners
				this.onmousemove = oldMouseMove;
				this.onmouseup   = oldMouseUp;

				return false;
			}

			// Call onstart
			onstart.call(this, arguments[0] || event);

			return false;
		}
	})(element.onmousedown);

	// override event attachers
	if (element.addEventListener)
		element.addEventListener = (function(original) {
			return function(event, listener, useCapture) {
				switch (event) {
					case "start":
						onstart = (function(old) {
							return function(event) { old.call(element,event); listener.call(element,event); }
						})(onstart);
						break;
					case "drag":
						ondrag = (function(old) {
							return function(event) { old.call(element,event); listener.call(element,event); }
						})(ondrag);
						break;
					case "stop":
						onstop = (function(old) {
							return function(event) { old.call(element,event); listener.call(element,event); }
						})(onstop);
						break;
					default:
						original.call(element, event, listener, useCapture);
				}
			}
		})(element.addEventListener);
	
	if (element.attachEvent)
		element.attachEvent = (function(original) {
			return function(event, listener) {
				switch (event) {
					case "onstart":
						onstart = (function(old) {
							return function(event) { old.call(element,event); listener.call(element,event); }
						})(onstart);
						break;
					case "ondrag":
						ondrag = (function(old) {
							return function(event) { old.call(element,event); listener.call(element,event); }
						})(ondrag);
						break;
					case "onstop":
						onstop = (function(old) {
							return function(event) { old.call(element,event); listener.call(element,event); }
						})(onstop);
						break;
					default:
						original.call(element, event, listener);
				}
			}
		})(element.attachEvent);
		
		
		if (window.attachEvent)
			window.attachEvent("onbeforeunload", function() {
				onstart = ondrag = onstop = element.onmousedown = element.addEventListener = element.attachEvent = null;
				element = null;
			});
}


// initialize Droppable in the global scope
var Droppable;

(function() {
	if (document.getBoxObjectFor) {
		function getOffset(element) {
			var box = document.getBoxObjectFor(element);
			return { x: box.x, y: box.y };
		}
	}
	else if (document.all && navigator.appName == "Microsoft Internet Explorer" && !window.opera) {
		function getOffset(element) {
			var range = document.body.createTextRange();
			range.moveToElementText(element);
			var rect = range.getBoundingClientRect();
			return { x: rect.left, y: rect.top };
		}
	}
	else {
		function getOffset(element) {
			var accumulator = arguments[1] || { x: 0, y: 0 };
			if (element && element != document.body) {
				accumulator.x += element.offsetLeft;
				accumulator.y += element.offsetTop;
				return getOffset(element.offsetParent, accumulator);
			}
			else {
				return accumulator;
			}
		}
	}

	// initialize private pointers to current target information
	var cTarget = null, cHover = null, cUnhover = null, cDrop = null;
	function hotSpots(x,y) {
		cTarget = cHover = cUnhover = cDrop = null;
	}

	// declare Droppable within the private scope
	Droppable = function(element) {
		// Calculate offset
		var offset = getOffset(element);

		// Calculate other edge offset
		var edge = { x: offset.x + element.offsetWidth, y: offset.y + element.offsetHeight };

		// Assign a finder function
		hotSpots = (function(old) {
			return function(x,y) {
				if (offset.x <= x && x <= edge.x && offset.y <= y && y <= edge.y) {
					cTarget  = element;
					cHover   = onhover;
					cUnhover = onunhover;
					cDrop    = ondrop;
				}
				else {
					old(x,y);
				}
			}
		})(hotSpots);

		// default event listeners
		function onhover(event) {
			event.dropTarget = element;
			if (element.onhover) element.onhover(event);
		}
		function onunhover(event) {
			event.dropTarget = element;
			if (element.onunhover) element.onunhover(event);
		}
		function ondrop(event) {
			event.dropTarget = element;
			if (element.ondrop) element.ondrop(event);
		}

		// override event attachers
		if (element.addEventListener)
			element.addEventListener = (function(original) {
				return function(event, listener, useCapture) {
					switch (event) {
						case "hover":
							onhover = (function(old) {
								return function(event) { old.call(element,event); listener.call(element,event); }
							})(onhover);
							break;
						case "unhover":
							onunhover = (function(old) {
								return function(event) { old.call(element,event); listener.call(element,event); }
							})(onunhover);
							break;
						case "drop":
							ondrop = (function(old) {
								return function(event) { old.call(element,event); listener.call(element,event); }
							})(ondrop);
							break;
						default:
							original.call(element, event, listener, useCapture);
					}				
				}
			})(element.addEventListener);

		if (element.attachEvent)
			element.attachEvent = (function(original) {
				return function(event, listener) {
					switch (event) {
						case "onhover":
							onhover = (function(old) {
								return function(event) { old.call(element,event); listener.call(element,event); }
							})(onhover);
							break;
						case "onunhover":
							onunhover = (function(old) {
								return function(event) { old.call(element,event); listener.call(element,event); }
							})(onunhover);
							break;
						case "ondrop":
							ondrop = (function(old) {
								return function(event) { old.call(element,event); listener.call(element,event); }
							})(ondrop);
							break;
						default:
							original.call(element, event, listener);
					}				
				}
			})(element.attachEvent);
	
	
		if (window.attachEvent)
			window.attachEvent("onbeforeunload", function() {
				hotSpots = onhover = onunhover = ondrop = element.addEventListener = element.attachEvent = cTarget = cHover = cUnhover = cDrop = null;
				element = null;
			});
	}

	// Setup a query method
	Droppable.query  = function(event) {	
		var oTarget  = cTarget,
		    oHover   = cHover,
		    oUnhover = cUnhover,
		    oDrop    = cDrop;

		var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft,
		    scrollTop  = document.documentElement.scrollTop  || document.body.scrollTop;
		

		hotSpots(event.clientX + scrollLeft, event.clientY + scrollTop);

		switch (event.type) {
			case "mousemove": // onhover & onunhover
				if (oTarget != null && oTarget != cTarget)
					oUnhover.call(oTarget, event);
				if (oTarget == null && cTarget != null)
					cHover.call(cTarget, event);
				break;
			case "mouseup": // ondrop
				if (cTarget != null) {
					cUnhover.call(cTarget, event);
					cDrop.call(cTarget, event);
				}
				break;
		}
	}
	
	Droppable.reset = function() {
		hotSpots = function(x,y) {
			cTarget = cHover = cUnhover = cDrop = null;
		}
		hotSpots();
	}
})();

// Fix the function prototype for IE5/Mac
if (typeof Function.prototype.apply == "undefined")
	Function.prototype.apply = function(scope, args) {
		if (!args) args = [];
		var index = 0, result;
		do { -- index } while (typeof scope[index] != "undefined");
		scope[index] = this;
	
		switch (args.length) {
			case 0:
				result = scope[index]();
				break;
			case 1:
				result = scope[index](args[0]);
				break;
			case 2:
				result = scope[index](args[0], args[1]);
				break;
			case 3:
				result = scope[index](args[0], args[1], args[2]);
				break;
			case 4:
				result = scope[index](args[0], args[1], args[2], args[3]);
				break;
			default:
				result = scope[index](args[0], args[1], args[2], args[3], args[4]);
				break;
		}
	
		delete scope[index];
		return result;
	}

if (typeof Function.prototype.call == "undefined")
	Function.prototype.call = function(scope) {
		var args = new Array(Math.max(arguments.length-1, 0));
		for (var i = 1; i < arguments.length; i++)
			args[i-1] = arguments[i];
		return this.apply(scope, args);
	}
Is there anyone who can fix it up for use with VB 3.8.4? Overall point to this is no drag = no text selection/no text selection = less posts being copied!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:13 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03289 seconds
  • Memory Usage 2,193KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete