Jump to content
php.lv forumi

JS "Unspecified Error" - ja izsauc dragDrop() pēc skrollēšan


Vilx-

Recommended Posts

Man ir lapa, kurā ir jāuztaisa viens mānīgs "slaideris". Tā kā lapa ir pasūtīta IE-only, tad es arī izmantoju IE pieejamos risinājumus. Compatibility nevajag. Lai panāktu slaideru efektus, es izmantoju eventus ondrag, ondragstart, ondragend. Lai saaktu dragoshanu, es ieksh onmousedown izsaucu objektam .dragDrop() metodi (citaadi man vajadzeetu izmantot bildes, bet tas ir lieki).

 

Viss ir labi, un notiek, liidz briidim, kad logs tiek paskrolleets horizontaali. Tad, naakamajaa onmousedown eventaa, .dragDrop() nobirst. Izmetas "Unspecified exception". To var paartvert, bet dragoshana nesaakas anyway. Naakamajaa onmousedown eventaa atkal viss notiek labi... Kas par joku?

Link to comment
Share on other sites

OK, rekur kods. java script:

var savedX, savedEl; // savedEl ir tikai debug noluukiem.

function InitiateDrag()
{
savedX = event.offsetX + event.srcElement.offsetLeft + 1;
savedEl = document.f_project.p_name;
z = 0;
try
{
	if ( event.srcElement )
		event.srcElement.dragDrop(); // Sheit lec errors, ja logs ir nupat horizontaali skrolleets
	else
		alert('Empty source element!');
}
catch(x)
{
  		alert('Facility code: ' + (x.number>>16 & 0x1FFF)+ ' Error code: '+(x.number & 0xFFFF));
}
}

function DragMiddle()
{
a = event.srcElement;
z = event.x-savedX;
if ( z < 0 )
	z = 0;
a.parentNode.parentNode.parentNode.style.left = z+'px';
savedEl.value = event.x + '; ' + event.offsetX+ '; ' + a.parentNode.parentNode.parentNode.style.left + '; ' + a.offsetLeft;
}
function DragLeft()
{
a = event.srcElement;
b = a.parentNode.parentNode.parentNode.style;
z = (event.x-savedX);
if ( z < 0 )
	z = 0;
newWidth = parseInt(b.width)+parseInt(b.left)-z;
if ( newWidth < 7 )
{
	z = z - (7 - newWidth);
	newWidth = 7;
}
b.width = newWidth+'px';
b.left = z+'px';
savedEl.value = b.width;
}
function DragRight()
{
a = event.srcElement;
b = a.parentNode.parentNode.parentNode.style;
delta = event.x-savedX-parseInt(b.left);
newWidth = parseInt(b.width)+delta;
if ( newWidth < 7 )
{
	delta = delta + (7 - newWidth);
	newWidth = 7;
}
b.width = newWidth+'px';
savedX += delta;
//b.left = z+'px';
savedEl.value = delta;
}

Peec tam HTML:

<div style="position: relative; left: 0px;">
		<table style="border-top: 1px solid black; border-bottom: 1px solid black; height: 14px; position: absolute; left: 20px; top: -8px; width: 100px" cellpadding="0" cellspacing="0"><tr>
			<td nowrap style="width: 3px; background-color: black; empty-cells: show; cursor: w-resize;"
					onmousedown="InitiateDrag();" ondragstart="DragLeft();"
					ondrag="DragLeft();" ondragend="DragLeft()"></td>
			<td style="background-color: cyan; empty-cells: show; cursor: move;"
					onmousedown="InitiateDrag();" ondragstart="DragMiddle();"
					ondrag="DragMiddle();" ondragend="DragMiddle()"><div style="width:1px"></div></td>
			<td nowrap style="width: 3px; background-color: black; empty-cells: show; cursor: e-resize;"
					onmousedown="InitiateDrag();" ondragstart="DragRight();"
					ondrag="DragRight();" ondragend="DragRight()"></td>
		</tr></table>
	</div>

Shitais HTML atkaartojas daudzaas vietaas, bet tam nav paaraakaas noziimes.

Edited by Vilx-
Link to comment
Share on other sites

OK, atradu workaround - saakumu JS kodam nomainam ar shito:

var savedX, savedEl, savedBar;

function InitiateDrag()
{
savedX = event.offsetX + event.srcElement.offsetLeft + 1;
savedEl = document.f_project.p_name;
try
{
	event.srcElement.dragDrop();
}
catch(x) // Magija - bez shitaa, ja logu scrollee horizontaali, dabon erroru pie naakamaas slaidoshanas. Uzmini nu...
{
		savedBar = event.srcElement;
		window.setTimeout("savedBar.fireEvent('onmousedown');",10,'JScript');
}
}

Tiesa - no kurienes tas magjiskais errors - velns vinju zin!

Link to comment
Share on other sites

×
×
  • Create New...