Slapyo
30 Nov 2006, 10:00 AM
I'm trying to implement the BasicDialog and I have it appearing. But if I click the button to show the dialog again I get a gray box the size of the dialog and the word false in it. I took the code from the Hello World Dialog example and when you click the button over and over it doesn't do anything like that. Here is the code I am using. Also, after clicking the close button in the dialog it moves the button that caused the dialog to show and the world false appears on the page, but no gray box.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Drag and Drop</title>
<script type="text/javascript" src="js/yahoo-dom-event.js"></script>
<script type="text/javascript" src="js/dragdrop-min.js"></script>
<script type="text/javascript" src="js/json.js"></script>
<script type="text/javascript" src="js/yui-ext-nogrid.js"></script>
<link rel="stylesheet" type="text/css" href="css/reset-fonts-grids-min.css">
<link rel="stylesheet" type="text/css" href="css/yui-ext.css">
<script type="text/javascript">
var ddImages = [];
var ddStrings = [];
var parentXY = [];
var childXY = [];
var offsetXY = [];
var strings = [];
var stringIndex;
YAHOO.util.DragDrop.prototype.constrainTo = function(constrainTo, pad, inContent){
if(typeof pad == 'number'){
pad = {left: pad, right:pad, top:pad, bottom:pad};
}
pad = pad || this.defaultPadding;
var b = getEl(this.getEl()).getBox();
var ce = getEl(constrainTo);
var c = ce.dom == document.body ? { x: 0, y: 0,
width: YAHOO.util.Dom.getViewportWidth(),
height: YAHOO.util.Dom.getViewportHeight()} : ce.getBox(inContent || false);
var topSpace = b.y - c.y;
var leftSpace = b.x - c.x;
this.resetConstraints();
this.setXConstraint(leftSpace - (pad.left||0), // left
c.width - leftSpace - b.width - (pad.right||0) //right
);
this.setYConstraint(topSpace - (pad.top||0), //top
c.height - topSpace - b.height - (pad.bottom||0) //bottom
);
}
function createString(stringText, stringSize, stringFont, stringColor) {
var stringXY = [0,0];
var newId = YAHOO.util.Dom.generateId(null, 'string');
stringText = stringText.replace(/(<([^>]+)>)/ig, '');
YAHOO.ext.DomHelper.append('parent', {tag:'div', id:newId, html:stringText, style: {width:'100px', position:'absolute', top:parentXY[1]+'px', left:parentXY[0]+'px', background:'yellow'}});
ddStrings.push(new YAHOO.util.DD(newId));
ddStrings[ddStrings.length-1].constrainTo('parent')
ddStrings[ddStrings.length-1].onDrag = function() {
updateXY(this);
updateStringXY(this);
}
document.getElementById(newId).ondblclick = function() {
editString(this);
}
strings.push([newId, stringText, stringSize, stringFont, stringColor, stringXY]);
alert(strings.toJSONString());
document.getElementById('stringText').value = 'Insert Text';
document.getElementById('editString').style.visibility = 'hidden';
}
function editString(el) {
stringIndex = searchStrings(el.id);
document.getElementById('editString').style.visibility = 'visible';
document.getElementById('editStringId').value = el.id;
document.getElementById('editStringText').value = strings[stringIndex][1];
document.getElementById('editStringSize').value = strings[stringIndex][2];
document.getElementById('editStringFont').value = strings[stringIndex][3];
document.getElementById('editStringColor').value = strings[stringIndex][4];
}
function updateString(stringId, stringText, stringSize, stringFont, stringColor) {
stringIndex = searchStrings(stringId);
document.getElementById(stringId).innerHTML = document.getElementById('editStringText').value;
strings[stringIndex][1] = document.getElementById('editStringText').value;
strings[stringIndex][2] = document.getElementById('editStringSize').value;
strings[stringIndex][3] = document.getElementById('editStringFont').value;
strings[stringIndex][4] = document.getElementById('editStringColor').value;
document.getElementById('editString').style.visibility = 'hidden';
document.getElementById('editStringId').value = '';
}
function deleteString(stringId) {
stringIndex = searchStrings(stringId);
strings.splice(stringIndex, 1);
document.getElementById('parent').removeChild(document.getElementById(stringId));
document.getElementById('editString').style.visibility = 'hidden';
document.getElementById('editStringId').value = '';
}
function updateStringXY(el) {
stringIndex = searchStrings(el.id);
parentXY = YAHOO.util.Dom.getXY('parent');
childXY = YAHOO.util.Dom.getXY(el.id);
offsetXY = [childXY[0] - parentXY[0], childXY[1] - parentXY[1]];
strings[stringIndex][5] = offsetXY;
}
function updateXY(el) {
parentXY = YAHOO.util.Dom.getXY('parent');
childXY = YAHOO.util.Dom.getXY(el.id);
offsetXY = [childXY[0] - parentXY[0], childXY[1] - parentXY[1]];
document.getElementById('parentXY').innerHTML = '(' + parentXY[0] + ', ' + parentXY[1] + ')'
document.getElementById('childXY').innerHTML = '(' + childXY[0] + ', ' + childXY[1] + ')'
document.getElementById('offsetXY').innerHTML = '(' + offsetXY[0] + ', ' + offsetXY[1] + ')'
}
function searchStrings(stringId) {
var i = 0;
var len = strings.length-1;
for(i; i<len; ++i) {
if (strings[i][0] == stringId) break;
}
return i;
}
window.onload = function () {
parentXY = YAHOO.util.Dom.getXY('parent');
ddImages[0] = new YAHOO.util.DD('child');
ddImages[0].constrainTo('parent');
ddImages[0].onDrag = function() {
updateXY(this);
}
document.getElementById('createButton').onclick = function () {
if (!dlgCreate) {
var dlgCreate = new YAHOO.ext.BasicDialog('createString', {
width: 300,
height: 300,
resizable: false,
shadow: true,
shim: true
});
dlgCreate.addKeyListener(27, dlgCreate.hide, dlgCreate);
dlgCreate.addButton('Close', dlgCreate.hide, dlgCreate);
}
dlgCreate.show();
}
}
</script>
</head>
<body>
<div style="width:100px; height:300px; float:left;"></div>
<div id="parent" style="width:300px; height:300px; float:left; background-color:red;">
<div id="child" style="width:50px; height:50px; float:left; background-color:lime;">Drag Me</div>
</div>
Parent (X,Y): <span id="parentXY"></span>
Child (X,Y): <span id="childXY"></span>
Offset (X,Y): <span id="offsetXY"></span>
<button id="createButton">Create String</button>
<div id="createString" style="visibility:hidden;position:absolute;top:0px;">
<div class="ydlg-hd">Hello Dialog</div>
<div class="ydlg-bd">
<label>Add String:
<input type="text" id="stringText" value="Insert Text" /></label></p>
<p class="clear"><label>Size:
<input type="text" id="stringSize" maxlength="4" size="1" value="12" /></label></p>
<label>Font:
<select id="stringFont" name="stringFontSelect"><option value='04'>04</option><option value='DirtyEgo'>DirtyEgo</option><option value='ProggyClean'>ProggyClean</option><option value='VeraMono'>VeraMono</option><option value='arial'>arial</option><option value='bitdust2'>bitdust2</option><option value='bmspa'>bmspa</option><option value='cod3x'>cod3x</option><option value='copyviol'>copyviol</option><option value='double01'>double01</option><option value='exprswy_free'>exprswy_free</option><option value='institution'>institution</option><option value='macromedia'>macromedia</option><option value='marvelouz'>marvelouz</option><option value='meresre'>meresre</option><option value='mplus-2p-black'>mplus-2p-black</option><option value='mplus-2p-bold'>mplus-2p-bold</option><option value='mplus-2p-light'>mplus-2p-light</option><option value='mplus-2p-medium'>mplus-2p-medium</option><option value='ocrae'>ocrae</option><option value='phoenix'>phoenix</option><option value='scifibit'>scifibit</option><option value='screenfox9'>screenfox9</option><option value='sevenet7'>sevenet7</option><option value='slkscr'>slkscr</option><option value='slkscrb'>slkscrb</option><option value='slkscre'>slkscre</option><option value='slkscreb'>slkscreb</option><option value='steelfis'>steelfis</option><option value='street'>street</option><option value='subway'>subway</option><option value='suede'>suede</option><option value='tahoma'>tahoma</option><option value='topaz'>topaz</option><option value='walkway'>walkway</option><option value='x'>x</option></select></label></p>
<label>Color: (hex#)
<input type="text" id="stringColor" value="bbeeff" maxlength="6" size="4" class="hexc" /></label></p>
Go:
<button id="stringButton" onclick="createString(document.getElementById('stringText').value, document.getElementById('stringSize').value, document.getElementById('stringFont').value, document.getElementById('stringColor').value);">Create String</button></p>
</div>
</div>
<div id="editString" style="text-align:left; float:left; visibility:hidden;">
<input type="hidden" id="editStringId" />
<label>Edit String:
<input type="text" id="editStringText" value="Insert Text" /></label></p>
<p class="clear"><label>Size:
<input type="text" id="editStringSize" maxlength="4" size="1" value="12" /></label></p>
<label>Font:
<select id="editStringFont" name="editStringFontSelect"><option value='04'>04</option><option value='DirtyEgo'>DirtyEgo</option><option value='ProggyClean'>ProggyClean</option><option value='VeraMono'>VeraMono</option><option value='arial'>arial</option><option value='bitdust2'>bitdust2</option><option value='bmspa'>bmspa</option><option value='cod3x'>cod3x</option><option value='copyviol'>copyviol</option><option value='double01'>double01</option><option value='exprswy_free'>exprswy_free</option><option value='institution'>institution</option><option value='macromedia'>macromedia</option><option value='marvelouz'>marvelouz</option><option value='meresre'>meresre</option><option value='mplus-2p-black'>mplus-2p-black</option><option value='mplus-2p-bold'>mplus-2p-bold</option><option value='mplus-2p-light'>mplus-2p-light</option><option value='mplus-2p-medium'>mplus-2p-medium</option><option value='ocrae'>ocrae</option><option value='phoenix'>phoenix</option><option value='scifibit'>scifibit</option><option value='screenfox9'>screenfox9</option><option value='sevenet7'>sevenet7</option><option value='slkscr'>slkscr</option><option value='slkscrb'>slkscrb</option><option value='slkscre'>slkscre</option><option value='slkscreb'>slkscreb</option><option value='steelfis'>steelfis</option><option value='street'>street</option><option value='subway'>subway</option><option value='suede'>suede</option><option value='tahoma'>tahoma</option><option value='topaz'>topaz</option><option value='walkway'>walkway</option><option value='x'>x</option></select></label></p>
<label>Color: (hex#)
<input type="text" id="editStringColor" value="bbeeff" maxlength="6" size="4" class="hexc" /></label></p>
Go:
<button id="editStringButton" onclick="updateString(document.getElementById('editStringId').value, document.getElementById('editStringText').value, document.getElementById('editStringSize').value, document.getElementById('editStringFont').value, document.getElementById('editStringColor').value);">Edit String</button> <button id="editStringDelete" onclick="deleteString(document.getElementById('editStringId').value);">Delete String</button></p>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Drag and Drop</title>
<script type="text/javascript" src="js/yahoo-dom-event.js"></script>
<script type="text/javascript" src="js/dragdrop-min.js"></script>
<script type="text/javascript" src="js/json.js"></script>
<script type="text/javascript" src="js/yui-ext-nogrid.js"></script>
<link rel="stylesheet" type="text/css" href="css/reset-fonts-grids-min.css">
<link rel="stylesheet" type="text/css" href="css/yui-ext.css">
<script type="text/javascript">
var ddImages = [];
var ddStrings = [];
var parentXY = [];
var childXY = [];
var offsetXY = [];
var strings = [];
var stringIndex;
YAHOO.util.DragDrop.prototype.constrainTo = function(constrainTo, pad, inContent){
if(typeof pad == 'number'){
pad = {left: pad, right:pad, top:pad, bottom:pad};
}
pad = pad || this.defaultPadding;
var b = getEl(this.getEl()).getBox();
var ce = getEl(constrainTo);
var c = ce.dom == document.body ? { x: 0, y: 0,
width: YAHOO.util.Dom.getViewportWidth(),
height: YAHOO.util.Dom.getViewportHeight()} : ce.getBox(inContent || false);
var topSpace = b.y - c.y;
var leftSpace = b.x - c.x;
this.resetConstraints();
this.setXConstraint(leftSpace - (pad.left||0), // left
c.width - leftSpace - b.width - (pad.right||0) //right
);
this.setYConstraint(topSpace - (pad.top||0), //top
c.height - topSpace - b.height - (pad.bottom||0) //bottom
);
}
function createString(stringText, stringSize, stringFont, stringColor) {
var stringXY = [0,0];
var newId = YAHOO.util.Dom.generateId(null, 'string');
stringText = stringText.replace(/(<([^>]+)>)/ig, '');
YAHOO.ext.DomHelper.append('parent', {tag:'div', id:newId, html:stringText, style: {width:'100px', position:'absolute', top:parentXY[1]+'px', left:parentXY[0]+'px', background:'yellow'}});
ddStrings.push(new YAHOO.util.DD(newId));
ddStrings[ddStrings.length-1].constrainTo('parent')
ddStrings[ddStrings.length-1].onDrag = function() {
updateXY(this);
updateStringXY(this);
}
document.getElementById(newId).ondblclick = function() {
editString(this);
}
strings.push([newId, stringText, stringSize, stringFont, stringColor, stringXY]);
alert(strings.toJSONString());
document.getElementById('stringText').value = 'Insert Text';
document.getElementById('editString').style.visibility = 'hidden';
}
function editString(el) {
stringIndex = searchStrings(el.id);
document.getElementById('editString').style.visibility = 'visible';
document.getElementById('editStringId').value = el.id;
document.getElementById('editStringText').value = strings[stringIndex][1];
document.getElementById('editStringSize').value = strings[stringIndex][2];
document.getElementById('editStringFont').value = strings[stringIndex][3];
document.getElementById('editStringColor').value = strings[stringIndex][4];
}
function updateString(stringId, stringText, stringSize, stringFont, stringColor) {
stringIndex = searchStrings(stringId);
document.getElementById(stringId).innerHTML = document.getElementById('editStringText').value;
strings[stringIndex][1] = document.getElementById('editStringText').value;
strings[stringIndex][2] = document.getElementById('editStringSize').value;
strings[stringIndex][3] = document.getElementById('editStringFont').value;
strings[stringIndex][4] = document.getElementById('editStringColor').value;
document.getElementById('editString').style.visibility = 'hidden';
document.getElementById('editStringId').value = '';
}
function deleteString(stringId) {
stringIndex = searchStrings(stringId);
strings.splice(stringIndex, 1);
document.getElementById('parent').removeChild(document.getElementById(stringId));
document.getElementById('editString').style.visibility = 'hidden';
document.getElementById('editStringId').value = '';
}
function updateStringXY(el) {
stringIndex = searchStrings(el.id);
parentXY = YAHOO.util.Dom.getXY('parent');
childXY = YAHOO.util.Dom.getXY(el.id);
offsetXY = [childXY[0] - parentXY[0], childXY[1] - parentXY[1]];
strings[stringIndex][5] = offsetXY;
}
function updateXY(el) {
parentXY = YAHOO.util.Dom.getXY('parent');
childXY = YAHOO.util.Dom.getXY(el.id);
offsetXY = [childXY[0] - parentXY[0], childXY[1] - parentXY[1]];
document.getElementById('parentXY').innerHTML = '(' + parentXY[0] + ', ' + parentXY[1] + ')'
document.getElementById('childXY').innerHTML = '(' + childXY[0] + ', ' + childXY[1] + ')'
document.getElementById('offsetXY').innerHTML = '(' + offsetXY[0] + ', ' + offsetXY[1] + ')'
}
function searchStrings(stringId) {
var i = 0;
var len = strings.length-1;
for(i; i<len; ++i) {
if (strings[i][0] == stringId) break;
}
return i;
}
window.onload = function () {
parentXY = YAHOO.util.Dom.getXY('parent');
ddImages[0] = new YAHOO.util.DD('child');
ddImages[0].constrainTo('parent');
ddImages[0].onDrag = function() {
updateXY(this);
}
document.getElementById('createButton').onclick = function () {
if (!dlgCreate) {
var dlgCreate = new YAHOO.ext.BasicDialog('createString', {
width: 300,
height: 300,
resizable: false,
shadow: true,
shim: true
});
dlgCreate.addKeyListener(27, dlgCreate.hide, dlgCreate);
dlgCreate.addButton('Close', dlgCreate.hide, dlgCreate);
}
dlgCreate.show();
}
}
</script>
</head>
<body>
<div style="width:100px; height:300px; float:left;"></div>
<div id="parent" style="width:300px; height:300px; float:left; background-color:red;">
<div id="child" style="width:50px; height:50px; float:left; background-color:lime;">Drag Me</div>
</div>
Parent (X,Y): <span id="parentXY"></span>
Child (X,Y): <span id="childXY"></span>
Offset (X,Y): <span id="offsetXY"></span>
<button id="createButton">Create String</button>
<div id="createString" style="visibility:hidden;position:absolute;top:0px;">
<div class="ydlg-hd">Hello Dialog</div>
<div class="ydlg-bd">
<label>Add String:
<input type="text" id="stringText" value="Insert Text" /></label></p>
<p class="clear"><label>Size:
<input type="text" id="stringSize" maxlength="4" size="1" value="12" /></label></p>
<label>Font:
<select id="stringFont" name="stringFontSelect"><option value='04'>04</option><option value='DirtyEgo'>DirtyEgo</option><option value='ProggyClean'>ProggyClean</option><option value='VeraMono'>VeraMono</option><option value='arial'>arial</option><option value='bitdust2'>bitdust2</option><option value='bmspa'>bmspa</option><option value='cod3x'>cod3x</option><option value='copyviol'>copyviol</option><option value='double01'>double01</option><option value='exprswy_free'>exprswy_free</option><option value='institution'>institution</option><option value='macromedia'>macromedia</option><option value='marvelouz'>marvelouz</option><option value='meresre'>meresre</option><option value='mplus-2p-black'>mplus-2p-black</option><option value='mplus-2p-bold'>mplus-2p-bold</option><option value='mplus-2p-light'>mplus-2p-light</option><option value='mplus-2p-medium'>mplus-2p-medium</option><option value='ocrae'>ocrae</option><option value='phoenix'>phoenix</option><option value='scifibit'>scifibit</option><option value='screenfox9'>screenfox9</option><option value='sevenet7'>sevenet7</option><option value='slkscr'>slkscr</option><option value='slkscrb'>slkscrb</option><option value='slkscre'>slkscre</option><option value='slkscreb'>slkscreb</option><option value='steelfis'>steelfis</option><option value='street'>street</option><option value='subway'>subway</option><option value='suede'>suede</option><option value='tahoma'>tahoma</option><option value='topaz'>topaz</option><option value='walkway'>walkway</option><option value='x'>x</option></select></label></p>
<label>Color: (hex#)
<input type="text" id="stringColor" value="bbeeff" maxlength="6" size="4" class="hexc" /></label></p>
Go:
<button id="stringButton" onclick="createString(document.getElementById('stringText').value, document.getElementById('stringSize').value, document.getElementById('stringFont').value, document.getElementById('stringColor').value);">Create String</button></p>
</div>
</div>
<div id="editString" style="text-align:left; float:left; visibility:hidden;">
<input type="hidden" id="editStringId" />
<label>Edit String:
<input type="text" id="editStringText" value="Insert Text" /></label></p>
<p class="clear"><label>Size:
<input type="text" id="editStringSize" maxlength="4" size="1" value="12" /></label></p>
<label>Font:
<select id="editStringFont" name="editStringFontSelect"><option value='04'>04</option><option value='DirtyEgo'>DirtyEgo</option><option value='ProggyClean'>ProggyClean</option><option value='VeraMono'>VeraMono</option><option value='arial'>arial</option><option value='bitdust2'>bitdust2</option><option value='bmspa'>bmspa</option><option value='cod3x'>cod3x</option><option value='copyviol'>copyviol</option><option value='double01'>double01</option><option value='exprswy_free'>exprswy_free</option><option value='institution'>institution</option><option value='macromedia'>macromedia</option><option value='marvelouz'>marvelouz</option><option value='meresre'>meresre</option><option value='mplus-2p-black'>mplus-2p-black</option><option value='mplus-2p-bold'>mplus-2p-bold</option><option value='mplus-2p-light'>mplus-2p-light</option><option value='mplus-2p-medium'>mplus-2p-medium</option><option value='ocrae'>ocrae</option><option value='phoenix'>phoenix</option><option value='scifibit'>scifibit</option><option value='screenfox9'>screenfox9</option><option value='sevenet7'>sevenet7</option><option value='slkscr'>slkscr</option><option value='slkscrb'>slkscrb</option><option value='slkscre'>slkscre</option><option value='slkscreb'>slkscreb</option><option value='steelfis'>steelfis</option><option value='street'>street</option><option value='subway'>subway</option><option value='suede'>suede</option><option value='tahoma'>tahoma</option><option value='topaz'>topaz</option><option value='walkway'>walkway</option><option value='x'>x</option></select></label></p>
<label>Color: (hex#)
<input type="text" id="editStringColor" value="bbeeff" maxlength="6" size="4" class="hexc" /></label></p>
Go:
<button id="editStringButton" onclick="updateString(document.getElementById('editStringId').value, document.getElementById('editStringText').value, document.getElementById('editStringSize').value, document.getElementById('editStringFont').value, document.getElementById('editStringColor').value);">Edit String</button> <button id="editStringDelete" onclick="deleteString(document.getElementById('editStringId').value);">Delete String</button></p>
</div>
</body>
</html>