SourceForge: tilescape/tilescape: changeset 23:c901f4bf86cc
Fixed drag bug at least on Eclipse internal browser
authorkato
Thu Apr 02 22:10:57 2009 +0300 (7 months ago)
changeset 23c901f4bf86cc
parent 21d70676016431
child 24ad80d0da68d5
Fixed drag bug at least on Eclipse internal browser
js/townfieldsgame.js
     1.1 --- a/js/townfieldsgame.js	Wed Apr 01 22:00:38 2009 +0300
     1.2 +++ b/js/townfieldsgame.js	Thu Apr 02 22:10:57 2009 +0300
     1.3 @@ -84,6 +84,24 @@
     1.4    return false; // just dont let a custom-control tile to be dragged
     1.5  }
     1.6  
     1.7 +function _setHandler(eventName, handlerFunction) {
     1.8 +	window[eventName + 'Was'] = [ document[eventName], window[ eventName + 'Was' ] ];
     1.9 +	document[eventName] = handlerFunction;
    1.10 +}
    1.11 +
    1.12 +function _resetHandler(eventName) {
    1.13 +	var handlerStack = window[eventName + 'Was'];
    1.14 +	if( handlerStack ) {
    1.15 +		if(handlerStack.length > 1)
    1.16 +			window[ eventName + 'Was' ] = handlerStack[1];
    1.17 +		else
    1.18 +			delete window[ eventName + 'Was' ];
    1.19 +		document[eventName] = handlerStack[0];
    1.20 +	} else {
    1.21 +		document[eventName] = null;
    1.22 +	}
    1.23 +}
    1.24 +
    1.25  function getMousePos(evt) {
    1.26    /* requires a mousedown or mousemove event */
    1.27    /* returns absolute {x,y} or false on failure */
    1.28 @@ -117,12 +135,10 @@
    1.29    if( at ) {
    1.30      window.mouseDownAt = at;
    1.31      if( document.onmouseup != TownFieldsGame_mouseUp ) {
    1.32 -      window.wasMouseUp = document.onmouseup;
    1.33 -      document.onmouseup = TownFieldsGame_mouseUp;
    1.34 +            _setHandler('onmouseup', TownFieldsGame_mouseUp);
    1.35      }
    1.36      if( document.onmousemove != TownFieldsGame_mouseMove ) {
    1.37 -      window.wasMouseMove = document.onmousemove;
    1.38 -      document.onmousemove = TownFieldsGame_mouseMove;
    1.39 +            _setHandler('onmousemove', TownFieldsGame_mouseMove);
    1.40      }
    1.41      var elem = evt.target;
    1.42      if( elem.ondragstart != TownFieldsGame_mouseDragStart ) {
    1.43 @@ -206,28 +222,21 @@
    1.44  }
    1.45  
    1.46  function TownFieldsGame_mouseUp(evt) {
    1.47 +        _resetHandler('onmouseup');
    1.48 +        _resetHandler('onmousemove');
    1.49 +	var elem = evt.target;
    1.50 +    if( elem.ondragstart == TownFieldsGame_mouseDragStart ) {
    1.51 +    	if( window.wasDragStart ) {
    1.52 +    		elem.ondragstart = window.wasDragStart;
    1.53 +    	} else {
    1.54 +    		delete window['ondragstart'];
    1.55 +    	}
    1.56 +    }
    1.57 +	delete window['wasDragStart'];
    1.58 +
    1.59 +
    1.60    var at = getMousePos(evt);
    1.61    if( at ) {
    1.62 -    if( document.onmouseup == TownFieldsGame_mouseUp ) {
    1.63 -	if( window.wasMouseUp )
    1.64 -	  document.onmouseup = window.wasMouseUp;
    1.65 -	else
    1.66 -	  delete document['onmouseup'];
    1.67 -	delete window['wasMouseUp'];
    1.68 -    }
    1.69 -    if( document.onmousemove == TownFieldsGame_mouseMove ) {
    1.70 -	if( window.wasMouseMove )
    1.71 -	  document.onmousemove = window.wasMouseMove;
    1.72 -	else
    1.73 -	  delete document['onmousemove'];
    1.74 -	delete window['wasMouseMove'];
    1.75 -    }
    1.76 -    var elem = evt.target;
    1.77 -    if( elem.ondragstart == TownFieldsGame_mouseDragStart ) {
    1.78 -	elem.ondragstart = window.wasDragStart;
    1.79 -	delete window['wasDragStart'];
    1.80 -    }
    1.81 -
    1.82      window.mouseMovedTo = at;
    1.83  
    1.84      var piece = document.getElementById('floatingPiece');