I know this may be a duplicate question. I'm new in this field.I have one leaflet map for Kerala state. I'm drawing this using the goejson using leaflet. So my function is if user clicks on any district it get zoom to the map box. it is working fine. The what is my problem is i have on table left side of map. it is the list of all districts in Kerala. i want to click on this name in table ie for eg if the user clicks THIRUVANANTHAPURAM the map should zoom to THIRUVANANTHAPURAM.
Please have a look at below picture.
In this picture fig 1 is the Kerala map that i have created. in that map if clicks any district( blue dotted all polygons are one district) it gets zoom to show that districts with some points. the fig 2 shows this thing. this is working fine.
the left side is table of contents as all district name in Kerala. what i want to do na if the user clicks any name in left side table map should get zoom like fig 2 as corresponding district .
please have alook at my below code.
HTML
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<link rel="stylesheet" href="leaflet/leaflet.css"/>
<script src="leaflet/leaflet.js"></script>
<script src="leaflet/leaflet-src.js"></script>
<script src="leaflet/geoGson.js"></script><!-- geo json to draw the map-->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="./leaflet/locations/locationGeoGson.js"></script><!-- geo json to draw the points on each district-->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDCePQZCvtV-rHrEShq2gOaXUvqMn9bUU0" async defer></script>
<script src='https://unpkg.com/leaflet.gridlayer.googlemutant#latest/Leaflet.GoogleMutant.js'></script>
</head>
<body>
<table width="100%" border="1">
<tr>
<td width="20%">
<table width="100%" border="0" id="list">
<tr>
<td colspan="2" style="color: red; font-size: 20px;font-weight: bolder;">DISTRICT</td>
</tr>
<tr style="height: 40px;">
<td width="100%" colspan="2"> <img src="./images/back.png"height="40px" /> </td>
</tr>
<tr style="height: 40px;">
<td width="10%">1</td>
<td width="90%"><a href="#" >THIRUVANANTHAPURAM</a></td>
</tr>
<tr style="height: 40px;">
<td>2</td>
<td>KOLLAM</td>
</tr>
<tr style="height: 40px;">
<td>3</td>
<td>PATHANAMTHITTA</td>
</tr>
<tr style="height: 40px;">
<td>4</td>
<td>ALAPPUZHA</td>
</tr>
<tr style="height: 40px;">
<td>5</td>
<td>KOTTAYAM</td>
</tr>
<tr style="height: 40px;">
<td>6</td>
<td>IDUKKI</td>
</tr>
<tr style="height: 40px;">
<td>7</td>
<td>ERNAKULAM</td>
</tr>
<tr style="height: 40px;">
<td>8</td>
<td>THRISSUR</td>
</tr>
<tr style="height: 40px;">
<td>9</td>
<td>PALAKKAD</td>
</tr>
<tr style="height: 40px;">
<td>10</td>
<td>MALAPPURAM</td>
</tr>
<tr style="height: 40px;">
<td>11</td>
<td>KOZHIKODE</td>
</tr>
<tr style="height: 40px;">
<td>12</td>
<td>WAYANAD</td>
</tr>
<tr style="height: 40px;">
<td>13</td>
<td>KANNUR</td>
</tr>
<tr style="height: 40px;">
<td>14</td>
<td>KASARAGOD</td>
</tr>
</table>
</td>
<td width="30%">
<div id="map" style="border: 1px solid red;height: 670px;width: 100%; " align="center"> </div>
</td>
<td width="25%">
<table width="100%" border="0">
<tr>
<td colspan="2" style="color: red; font-size: 20px;font-weight: bolder;">CATEGORY</td>
</tr>
<tr style="height: 40px;">
<td width="10%">1</td>
<td width="90%">GUEST HOUSES</td>
</tr>
<tr style="height: 40px;">
<td>2</td>
<td>HOTELS</td>
</tr>
<tr style="height: 40px;">
<td>3</td>
<td>MOTELS</td>
</tr>
<tr style="height: 40px;">
<td>4</td>
<td>TAMARINDS</td>
</tr>
<tr style="height: 40px;">
<td>5</td>
<td>PARKS</td>
</tr>
<tr style="height: 40px;">
<td>6</td>
<td>PALACES</td>
</tr>
<tr style="height: 40px;">
<td>7</td>
<td>BOAT CLUBS</td>
</tr>
<tr style="height: 40px;">
<td>8</td>
<td>TOURIST AMENITY CENTERS</td>
</tr>
<tr style="height: 40px;">
<td>9</td>
<td>INFORMATION CENTERS</td>
</tr>
<tr>
<td>
<div id="data"> </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
MY JS
<script type="text/javascript">
var statesData="";
var districtLayer="",Kerala_Layer_Group="";
var pointJson="";
var map = L.map('map');
map.setView([10.54265308,76.13877106], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
L.control.scale().addTo(map);
var customControl = L.Control.extend({
options: {
position: 'topleft'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom');
container.style.backgroundColor = 'white';
container.style.backgroundImage = "url(./Images/back_multim.jpg)";
container.style.backgroundSize = "30px 30px";
container.style.width = '30px';
container.style.height = '30px';
container.onclick = function(){
console.log('buttonClicked');
map.removeLayer(pointJson);
map.setView([10.54265308,76.13877106], 7);
}
return container;
}
});
map.addControl(new customControl());
// control that shows state info on hover
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>KERALA 2016</h4>' + (props ?
' ' + props.district + ' '
: 'Hover over a district');
};
info.addTo(map);
// get color depending on population density value
function getColor(d) {
return d=="Alappuzha"?'#cb41ea':
d=="Ernakulam"?'#4082ec':
d=="Idukki"?'#5553d4':
d=="Kannur"?'#e04b49':
d=="Kasargod"?'#28edc6':
d=="Kollam"?'#26b5dc':
d=="Kottayam"?'#6316d0':
d=="Kozhikkode"?'#e281a7':
d=="Malappuram"?'#54e254':
d=="Palakkad"?'#6ed095':
d=="Pathanamthitta"?'#dab933':
d=="Thiruvananthapuram"?'#69d91d':
d=="Thrissur"?'#ee40c9':
d=="Wayanad"?'#e99b67':'#000';
}
function style(feature) {
return {
weight: 1.5,
opacity: 1,
//color: 'black',
dashArray: '2',
fillOpacity: 0.0,
//fillColor: getColor(feature.properties.district)
};
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 1,
//color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
var geojson;
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
console.log(e.target);
map.fitBounds(e.target.getBounds());
addGeoJsonToMap(e);
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
var statesData=GeoDataJson;
geojson = L.geoJson(statesData, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
function addGeoJsonToMap(e){
//alert("im here");
var layerp = e.target;
map.removeLayer(pointJson);
var districtName=layerp.feature.properties.district;//alert(districtName);
console.log(districtName);
switch(districtName){
case 'Thiruvananthapuram':
districtNameJson=Point_Thiruvananthapuram;
break;
case 'Kollam':
districtNameJson=Point_Kollam;
break;
case 'Alappuzha':
districtNameJson=Point_Alappuzha;
break;
case 'Pathanamthitta':
districtNameJson=Point_Pathanamthitta;
break;
}
var dataJson=districtNameJson;
//var dataJson=
pointJson = new L.GeoJSON(dataJson, {
style: stylePoint,
onEachFeature: addClickFeature
});
map.addLayer(pointJson);
}
function stylePoint(feature) {
return {
weight: 1.5,
opacity: 1,
color: 'red',
dashArray: '2',
fillOpacity: 1.0,
fillColor: getColor(feature.properties.district)
};
}
function addClickFeature(feature, layer) {
layer.on({
mouseover: openPopup,
mouseout: closePopup,
click: clickPonit
});
}
function openPopup(e){
var layerp = e.target;
var latLong=layerp.feature.geometry.coordinates;
var HtmlContents="";
HtmlContents+="<a href='#'>"+layerp.feature.properties.category+"<img src='./images/download.png'></a>"
layerp.bindPopup(HtmlContents, {
closeButton: true,
offset: L.point(0, -20)
});
layerp.addTo(map);
var templatlng =new L.LatLng(latLong[1],latLong[0]);
var popup = L.popup()
.setLatLng(templatlng)
.setContent(HtmlContents);
map.openPopup(popup);
}
function clickPonit(e){
var layer = e.target;
info.update = function (props) {
this._div.innerHTML = '<h4>KERALA 2016</h4>' + (layer.feature.properties.category);
};
info.addTo(map);
}
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 10, 20, 50, 100, 200, 500, 1000],
labels = [],
from, to;
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<i style="background:' + getColor(from + 1) + '"></i> ' +
from + (to ? '–' + to : '+'));
}
div.innerHTML = labels.join('<br>');
return div;
};
</script>
Please help me to solve this, i have googled it but i didn't find the ans for this. this is one of the example . But i don't want to do like this my thing because entirely different from this.
i have added this line
<table width="100%" border="0" id="list">
and in my js i have added
var list = document.getElementById("list");
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
var li = document.createElement("li"),
a = document.createElement("a"),
content = allProps(feature.properties.district);
// Create the "button".
a.innerHTML = content;
a.href = "#";
a.layer = layer; // Store a reference to the actual layer.
a.addEventListener("click", function (event) {
event.preventDefault(); // Prevent the link from scrolling the page.
map.fitBounds(this.layer.getBounds());
layer.openPopup();
});
li.appendChild(a);
list.appendChild(li);
layer.bindPopup(content);
}
function allProps(props) {
var result = [];
result.push(props);
return result.join(", ");
}
now the problem is solved in my case.
Related
I got few buttons question and would like to change the txt color after the value changed. ex: begin with "select" --> changes to "positive" (answer).
where should I make the loop to check if the value was changed? how?
I'm stuck on this code and any help will be good.
var answers = ['Positive', 'Negative'];
if (typeof ARRAY_OF_QUESTIONS[i].header == 'undefined') {
$('#questionsTable tbody').append(Utils.processTemplate("#rowTemplate tbody", data));
$("#" + id + "-inspectionResult").text(data.inspectionResult || 'Select');
$("#" + id + "-inspectionResult").click(resultHandler.bind(data));
updateActiveStatus(data);
commentvisibilitymanager(data);
if(ARRAY_OF_QUESTIONS[i].header == 'undefined'){
$("#" + id + "-inspectionResult").text(data.inspectionResult || 'Select').addClass(asnwers)
} // loop check for value
if (asnwers) {
}
}
else {
$('#questionsTable tbody').append(Utils.processTemplate("#sectionRowTemplate tbody", data));
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table frame="box" id="questionnaireHeader" width="100%'" position="fixed">
<tr height="40px" style="background: #006b54; color:white" >
<td width="70%" align="center" style="align:center">Question</div>
<td width="30%" align="center" style="align:center">Result</td>
</tr>
</table>
<table frame="box" width="100%" id="questionsTable">
<tbody>
</tbody>
</table>
<!-- This hosts all HTML templates that will be used inside the JavaScript code -->
<table class ="cls-{id} active-{active}" style="display:none;" width="100%" id="rowTemplate">
<tr class ="bb cls-{id} active-{active}">
<td class="active-{active}" id="{id}-question" width="70%">{question}</td>
<td class="cls-{id} active-{active}" style="border-style:hidden; font-family: 'Poppins', sans-serif !important;" width="30%">
<button class="buttons" step="0.01" data-clear-btn="false" style="background: #006b54; border radius: px; color:white !important ;" id="{id}-inspectionResult"></button>
</td>
</tr>
</table>
<div id="projectPopUp" class="popup-window" style="display:none;">
<div class="popuptitle" id="details-name"></div>
<table id="detailsgrid">
<tbody></tbody>
</table>
<div>
<button class="smallButton" onClick="closePopup()">Close</button>
</div>
</div>
<table style="display:none;" id="popupPersonTemplate">
<tr class ="bb cls-{id}">
<td width="70%">{name}</td>
<td width="30%">
<button class="buttons" step="0.01" data-clear-btn="false" style="background: #006b54; color:white !important ;" id="{id}-status"></button>
</td>
</tr>
</table>
<!--closeProjectPopup()-->
<table style="display: none;" id="sectionRowTemplate">
<tr width="100%" class="bb cls-{id}-row2 sectionheader">
<td class="cls-{id}" colspan="3">{question}</td>
</tr>
</table>
its done!
var checkComplete = true;
var questionResults = data.employee_results;
for (var employee in questionResults){
if (questionResults[employee] == ''){
checkComplete = false;
}
}
if (checkComplete) {
//button
$("#" + id + "-inspectionResult").text('Done');
}
else {
$("#" + id + "-inspectionResult").text('Select');
}
}
else {
$('#questionsTable tbody').append(Utils.processTemplate("#sectionRowTemplate tbody", data));
}
I want to make a div block move on arrow buttons. But it doesn't work. I put the buttons in a table.
document.getElementById("upbutton").onclick = function up() {
var block = document.getElementById("block");
var dos = "30px";
var h = "630px";
block.style.position = "relative";
while (block.style.top > h) {
block.style.top = "300px" + dos + "px";
dos += "30px";
}
};
<div id="space">
<div id="block"></div>
<div id="arrows">
<table>
<tr>
<th class="arrow"></th>
<th class="arrow"><button id="upbutton"><img src="up.png"></button></th>
<th class="arrow"></th>
</tr>
<tr>
<td class="arrow"><button id="leftbutton"><img src="left.png"></button></td>
<td class="arrow"><button id="resetbutton"><img src="reset.jpg"></button></td>
<td class="arrow"><button id="rightbutton"><img src="right.png"></button></td>
</tr>
<tr>
<td class="arrow"></td>
<td class="arrow"><button id="downbutton"><img src="down.png"></button></td>
<td class="arrow"></td>
</tr>
</table>
</div>
</div>
There are lot of things wrong with your code
You cannot add string to an integer it will result to string
concatenation. If you add "300px"+ 10 it will result to
300px10 not 310px
I can't understand your logic what you are trying to do but
while (block.style.top > h) { will never pass as style of block will be in string again 0px at start and h is 630.
you have use parseInt(block.style.top) in while loop to compare.
Your div block has no width and height or color you can't see anything.
Here is my implementation of moving a div using arrows.
Store your position to a object pos var pos = {top:0,left:0};
then add events to your buttons
UP:
Update the pos.top+=dos value and apply it to the block.style.top = pos.top+'px';
document.getElementById("upbutton").onclick = function up() {
//Update if top is not equal to zero not allowed to go out of window.
if(pos.top!=0) {pos.top-=dos; block.style.top = pos.top+'px';}
};
Down:
Update the pos.top-=dos value and apply it to the block.style.top = pos.top+'px';
document.getElementById("downbutton").onclick = function down() {
if(pos.top<h) {pos.top+=dos; block.style.top = pos.top+'px';}
};
Left:
Update the pos.left-=dos value and apply it to the block.style.left = pos.left+'px';
document.getElementById("leftbutton").onclick = function left() {
if(pos.left!=0) {pos.left-=dos; block.style.left = pos.left+'px';}
};
Right:
Update the pos.left+=dos value and apply it to the block.style.left = pos.left+'px';
document.getElementById("rightbutton").onclick = function right() {
if(pos.top<h) {pos.left+=dos; block.style.left = pos.left+'px';}
};
SNIPPET
var dos = 30;
var h = 630;
var block = document.getElementById("block");
var pos = {top:0,left:0};
document.getElementById("upbutton").onclick = function up() {
if(pos.top!=0) {pos.top-=dos; block.style.top = pos.top+'px';}
};
document.getElementById("downbutton").onclick = function up() {
if(pos.top<h) {pos.top+=dos; block.style.top = pos.top+'px';}
};
document.getElementById("leftbutton").onclick = function up() {
if(pos.left!=0) {pos.left-=dos; block.style.left = pos.left+'px';}
};
document.getElementById("rightbutton").onclick = function up() {
if(pos.top<h) {pos.left+=dos; block.style.left = pos.left+'px';}
};
#block{
width:100px;
height:100px;
position:relative;
background-color:red;
}
#arrows{
position:relative;
z-index:10;
}
<div id="space">
<div id="block" style="top:0px"></div>
<div id="arrows">
<table>
<tr>
<th class="arrow"></th>
<th class="arrow"><button id="upbutton"><img src="up.png"></button></th>
<th class="arrow"></th>
</tr>
<tr>
<td class="arrow"><button id="leftbutton"><img src="left.png"></button></td>
<td class="arrow"><button id="resetbutton"><img src="reset.jpg"></button></td>
<td class="arrow"><button id="rightbutton"><img src="right.png"></button></td>
</tr>
<tr>
<td class="arrow"></td>
<td class="arrow"><button id="downbutton"><img src="down.png"></button></td>
<td class="arrow"></td>
</tr>
</table>
</div>
</div>
This is how I'd go about this:
var block = document.getElementById("block");
function adjustPos(dX, dY) {
block.style.left = parseInt(block.style.left) + dX + 'px';
block.style.top = parseInt(block.style.top) + dY + 'px';
}
document.getElementById("upbutton").onclick = () => adjustPos(0, -10);
document.getElementById("leftbutton").onclick = () => adjustPos(-10, 0);
document.getElementById("rightbutton").onclick = () => adjustPos(10, 0);
document.getElementById("downbutton").onclick = () => adjustPos(0, 10);
#block {
width: 10px;
height: 20px;
background-color: blue;
position: fixed;
}
<div id="space">
<div id="block" style="top: 100px; left: 100px;"></div>
<div id="arrows">
<table>
<tr>
<th class="arrow"></th>
<th class="arrow">
<button id="upbutton">⇑</button>
</th>
<th class="arrow"></th>
</tr>
<tr>
<td class="arrow">
<button id="leftbutton">⇐</button>
</td>
<td class="arrow">
<button id="resetbutton">ⓧ</button>
</td>
<td class="arrow">
<button id="rightbutton">⇒</button>
</td>
</tr>
<tr>
<td class="arrow"></td>
<td class="arrow">
<button id="downbutton">⇓</button>
</td>
<td class="arrow"></td>
</tr>
</table>
</div>
</div>
The key insight is that you need to parse the string as an int (this removes the trailing 'px'. Then you can add it back.
Also, your block needs to use position: fixed to be positioned wherever on the page.
This could be an start point.
var block = document.getElementById("block");
document.getElementById("upbutton").onclick = function up() {
adjustPos(0, -10);
};
document.getElementById("leftbutton").onclick = function up() {
adjustPos(-10, 0);
};
document.getElementById("rightbutton").onclick = function up() {
adjustPos(10, 0);
};
document.getElementById("downbutton").onclick = function up() {
adjustPos(0, 10);
};
document.getElementById("resetbutton").onclick = function up() {
block.style.left = 50 + 'px';
block.style.top = 50 + 'px';
};
function adjustPos(dX, dY) {
block.style.left = parseInt(block.style.left) + dX + 'px';
block.style.top = parseInt(block.style.top) + dY + 'px';
}
<div id="space" style="width:100px;height:100px">
<div id="block" style="background-color: black;position: relative;width: 10px;height: 10px; top:50px; left:50px"></div>
</div>
<div id="arrows">
<table>
<tr>
<th class="arrow"></th>
<th class="arrow"><button id="upbutton"><img src="up.png"></img></button></th>
<th class="arrow"></th>
</tr>
<tr>
<td class="arrow"><button id="leftbutton"><img src="left.png"></img></button></td>
<td class="arrow"><button id="resetbutton"><img src="reset.jpg"></img></button></td>
<td class="arrow"><button id="rightbutton"><img src="right.png"></img></button></td>
</tr>
<tr>
<td class="arrow"></td>
<td class="arrow"><button id="downbutton"><img src="down.png"></img></button></td>
<td class="arrow"></td>
</tr>
</table>
</div>
I have a call in the parent HTML which invokes a javascript call.
<div class="data">
<form:input title="Building" styleClass="content contractorDisable" maxlength="5" size="6" path="fireImpairForm.bldCode" />
<a href="javascript:winOpen('LookupLocation.htm','bld')">
<img src="image/search.gif" border="0" alt="Click here to find Building"></a>
</div>
The javascript used for the modal window previously was using a window.showModal where the code has been commented as shown in the javascript code below.
I am looking to have a replacement for this same call through Jquery and using the jQuery dialog code.
and this is the javascript call that is called which encapsulates a jquery dialog popup. Previously I was able to set a value in the parent input text value to whatever was selected in the modalDialog window using the return object of modalwindow.That code is now commented out to show what it was and what the implementation I am looking for in its place. I am looking for some replacement for that implementation using jQuery dialog. My Dailog is encapsulating another jsp which is a table so I am not able to return the value back to the parent form.
function winOpen(urlVal, type) {
var printNames = new Object();
var ind = [document.forms[0].elements["fireImpairForm.statusId"].selectedIndex].value;
ind = document.forms[0].elements["fireImpairForm.facility"].selectedIndex;
var facilityCode = document.forms[0].elements["fireImpairForm.facility"].item(ind).value;
var sub = facilityCode.substring(((facilityCode).indexOf("-")) + 1, (facilityCode).length);
var params = "?bldCode=" + document.forms[0].elements["fireImpairForm.bldCode"].value + "&floorCode=" + document.forms[0].elements["fireImpairForm.floorCode"].value + "&campusCode=" + sub + "&check=" + "check" + "&facilityCode=" + facilityCode;
/*
retObj = window.showModalDialog(urlVal+params,"","scroll:no;status:no;dialogWidth:620px;dialogHeight:600px;unadorned:yes;resizable=yes");
if (retObj != null) {
document.forms[0].elements["fireImpairForm.bldCode"].value=retObj.code;
}
*/
}
var page = urlVal + params;
var $dialog = $('<div></div>')
.html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: 625,
width: 500,
title: "Buildings"
});
$dialog.dialog('open');
}
The LookupLocation.htm spring controller returns a jsp
<BODY topmargin=0 leftmargin=0 bottommargin=0 rightmargin=0>
<center>
<form name="locForm">
<input type="hidden" name="code" />
<DIV style="overflow:auto;clear:both; width:100%; height:525px; border :1px solid;">
<TABLE onkeydown="if (event.keyCode=='13') return returnToParent()" cellpadding="0" cellspacing="1" id="resultTable" width="100%">
<TBODY>
<c:if test="${empty resultList}">
<tr>
<td bgcolor="buttonface"><b>No data found</b></td>
</tr>
</c:if>
<c:if test="${!empty resultList}">
<tr>
<td> </td>
</tr>
<tr>
<td class="label">Search:</td>
<td class="content">
<input name="searchFld" type="text" size=15 onChange="">
</td>
<td class="content">
<input type="button" value="Find" onclick="findString(document.locForm.searchFld.value)">
</td>
</tr>
<tr>
<td nowrap class="searchTableHeader" align="center" STYLE="color:white">Select</td>
<td nowrap class="searchTableHeader" align="center" STYLE="color:white">Location Code</td>
<td nowrap class="searchTableHeader" align="center" STYLE="color:white">Description</td>
</tr>
<c:set var="evenCount" value="${0}" />
<c:forEach var="result" varStatus="i" items="${resultList}">
<c:set var="evenCount" value="${evenCount+1}" />
<c:choose>
<c:when test="${evenCount % 2 == 0}">
<tr id='row${evenCount}' class="even_row">
</c:when>
<c:otherwise>
<tr id='row${evenCount}' class="odd_row">
</c:otherwise>
</c:choose>
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(${evenCount}); setLookupValuesOne("${result.code}");returnToParent();'>
</td>
<td width="15%" nowrap class="content">
<c:out value="${result.code}" />
</td>
<td nowrap class="content">
<c:out value="${result.description}" />
</td>
</tr>
</c:forEach>
</c:if>
</TBODY>
</TABLE>
</DIV>
</form>
</center>
</BODY>
Any help will be much appreciated.
I have looked at several implementation of jQuery Dialogs and I am not able to piece together how I can have parent form interaction between the jQuery Dialog.
UPDATED :adding the rendered HTML requested by Mark
Here is the updated rendered HTML.
Normal behaviour was , when radio button is selected, the window closed and returned the selected object which was set to a input value on the parent form but now the return object is not getting captured and I can not set the input value fireImpairForm.bldCode
<html>
<BODY topmargin=0 leftmargin=0 bottommargin=0 rightmargin=0>
<center>
<form name="locForm">
<input type="hidden" name="code" />
<DIV style="overflow:auto;clear:both; width:100%; height:525px; border :1px solid;">
<TABLE onkeydown="if (event.keyCode=='13') return returnToParent()" cellpadding="0" cellspacing="1" id="resultTable" width="100%">
<TBODY>
<tr>
<td> </td>
</tr>
<tr>
<td class="label">Search:</td>
<td class="content">
<input name="searchFld" type="text" size=15 onChange="">
</td>
<td class="content">
<input type="button" value="Find" onclick="findString(document.locForm.searchFld.value)">
</td>
</tr>
<tr>
<td nowrap class="searchTableHeader" align="center" STYLE="color:white">Select</td>
<td nowrap class="searchTableHeader" align="center" STYLE="color:white">Location Code</td>
<td nowrap class="searchTableHeader" align="center" STYLE="color:white">Description</td>
</tr>
<tr id='row1' class="odd_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(1); setLookupValuesOne("PC ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">PC </td>
<td nowrap class="content">10150 Place</td>
</tr>
<tr id='row2' class="even_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(2); setLookupValuesOne("ON ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">ON </td>
<td nowrap class="content">1019 Building</td>
</tr>
<tr id='row3' class="odd_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(3); setLookupValuesOne("OG ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">OG </td>
<td nowrap class="content">19137 Building</td>
</tr>
<tr id='row4' class="even_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(4); setLookupValuesOne("TO ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">TO </td>
<td nowrap class="content">2011 Building</td>
</tr>
<tr id='row5' class="odd_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(5); setLookupValuesOne("TT ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">TT </td>
<td nowrap class="content">30133 4 nw Street Building</td>
</tr>
<tr id='row6' class="even_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(6); setLookupValuesOne("TH ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">TH </td>
<td nowrap class="content">13939 Warehouse</td>
</tr>
<tr id='row7' class="odd_row">
<td width="5%" align="center" class="content">
<input type="radio" name="radioValue" onclick='highlight(7); setLookupValuesOne("N2 ");returnToParent();'>
</td>
<td width="15%" nowrap class="content">N2 </td>
<td nowrap class="content">40th Avenue Warehouse</td>
</tr>
</TBODY>
</TABLE>
</DIV>
</form>
</center>
</BODY>
</html>
Here the jscript calls if that helps.
I am having a time trying to format the three jscript calls . If you need it I will paste it somehow. They are not really important though for what I am asking. The first is highlighting grey and white background depending on selected row number odd or even. The next ones I have added
function returnToParent() {
//var defer=$.Deferred();
if (document.forms[0].code.value == null || document.forms[0].code.value == "") {
alert("Please select a row.");
return false;
}
var rowObj = new Object();
rowObj.code = document.forms[0].code.value;
if (window.showModalDialog) {
self.returnValue = rowObj;
} else {
//opener.setData(rowObj);
}
//defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false.
//$(window.opener.document).forms['dialogForm'].dailogFormVal.val=document.forms[0].code.value;
//$(window.opener.document).find().val(document.forms[0].code.value);
var parent = $(window.frameElement).parent();
parent.find("#dailogFormVal").val(document.forms[0].code.value);
$(this).dialog("close");
}
function setLookupValuesOne(codeValue) {
document.forms[0].code.value = codeValue;
var parent = $(window.frameElement).parent();
parent.find("#dailogFormVal").val(document.forms[0].code.value);
//$(window.parent.document.getElementById("dailogFormVal")).val(document.forms[0].code.value);
//$(window.opener.document).forms['dialogForm'].getElementById['dailogFormVal'].value=codeValue;
The finally ending "}" is not getting added to the jscript code.
Updated to show the modified jScript
console.clear();$dialog.append("<iframe id='dialogframe' style='border: 0px; width: 100%;height:100% '/>");$dialog.dialog({autoOpen: false, modal: true,width: "auto", height: "auto", title: "Buildings", buttons: [{
text: "Close", click: function() { $(this).dialog('close'); } }]});function winOpenDlg(urlVal, type) { var printNames = new Object(); var ind =[document.forms[0].elements["fireImpairForm.statusId"].selectedIndex].value; ind = document.forms[0].elements["fireImpairForm.facility"].selectedIndex; var facilityCode = document.forms[0].elements["fireImpairForm.facility"].item(ind).value; var sub = facilityCode.substring(((facilityCode).indexOf("-"))+1,(facilityCode).length); if (type == 'floor') { if (document.forms[0].elements["fireImpairForm.bldCode"].value.length <= 0) { alert('Please select a building.'); }else { var params="?bldCode="+document.forms[0].elements["fireImpairForm.bldCode"].value+"&campusCode="+sub+"&facilityCode="+facilityCode;
}
} else if (type == 'room') {
if (document.forms[0].elements["fireImpairForm.bldCode"].value.length <= 0) {
alert('Please select a building.');
}else if (document.forms[0].elements["fireImpairForm.floorCode"].value.length <= 0) {
alert('Please select a floor.');
}else {
var params="?bldCode="+document.forms[0].elements["fireImpairForm.bldCode"].value+"&floorCode="+document.forms[0].elements["fireImpairForm.floorCode"].value+"&campusCode="+sub+"&check="+"check"+"&facilityCode="+facilityCode;
}
} else {
var params="?campusCode="+sub+"&facilityCode="+facilityCode;
}var page = urlVal + params; $('#dialogframe').attr('src', page);// yours would do this // here I create a sample set of text to inject //var sample = '<div id="findem">Hi I am found</div>';var dialogBody = $("#dialogframe").contents().find("body");//$($dialog.find('#dialogframe')[0].contentWindow.document.body);//$('#dialogframe').attr('src', page);// yours would do this // I do this for simplicity and demonstration//dialogBody.html("<div id='original'>First Text </div>"); //dialogBody.append(sample);// add a click event to the dialog contents, you would do different things dialogBody.on('click', '[id^=row]', function() { console.log("triggered !!");
console.log(this.id + ":" + this.innerHTML); // id of element clicked document.forms[0].elements["fireImpairForm.bldCode"]=document.forms[0].elements[this.id].value;}); $dialog.dialog('open');}
Updated to show latest Javascript
I updated my code and removed any reference to my src location but even then the same error comes up.
EditFireImpair.htm?permitIk=301 Uncaught TypeError: Cannot read property 'contentWindow' of undefined
Defined below is the java script code I inserted almost unchanged from what you posted. The dialog does not open up as it does on your fiddle page.
<script>
console.clear();
var $dialog = $('#mydialog');
$dialog.append("<iframe id='dialogframe' style='border: 0px; width: 100%;height:100% '/>");;
$dialog.dialog({
autoOpen: false,
modal: true,
width: "auto",
height: "auto",
title: "Buildings",
buttons: [{
text: "Close Me",
click: function() {
$(this).dialog('close');
}
}]
});
function winOpenNewDlg(urlVal, type) {
var printNames = new Object();
var ind =[document.forms[0].elements["fireImpairForm.statusId"].selectedIndex].value;
ind = document.forms[0].elements["fireImpairForm.facility"].selectedIndex;
var facilityCode = document.forms[0].elements["fireImpairForm.facility"].item(ind).value;
var sub = facilityCode.substring(((facilityCode).indexOf("-"))+1,(facilityCode).length);
if (type == 'floor') {
if (document.forms[0].elements["fireImpairForm.bldCode"].value.length <= 0) {
alert('Please select a building.');
}else {
var params="?bldCode="+document.forms[0].elements["fireImpairForm.bldCode"].value+"&campusCode="+sub+"&facilityCode="+facilityCode;
}
} else if (type == 'room') {
if (document.forms[0].elements["fireImpairForm.bldCode"].value.length <= 0) {
alert('Please select a building.');
}else if (document.forms[0].elements["fireImpairForm.floorCode"].value.length <= 0) {
alert('Please select a floor.');
}else {
var params="?bldCode="+document.forms[0].elements["fireImpairForm.bldCode"].value+"&floorCode="+document.forms[0].elements["fireImpairForm.floorCode"].value+"&campusCode="+sub+"&check="+"check"+"&facilityCode="+facilityCode;
}
} else {
var params="?campusCode="+sub+"&facilityCode="+facilityCode;
}
var page = urlVal + params;
//$('#dialogframe').attr('src', page);// yours would do this
// here I create a sample set of text to inject
var sample = '<div id="findem">Hi I am found</div>';
var dialogBody = $($dialog.find('#dialogframe')[0].contentWindow.document.body);
// $('#dialogframe').attr('src', page);// yours would do this
// I do this for simplicity and demonstration
dialogBody.html("<div id='original'>First Text </div>");
dialogBody.append(sample);
// add a click event to the dialog contents, you would do different things
dialogBody.on('click', '*', function() {
console.log("triggered !!");
console.log(this.id + ":" + this.innerHTML); // id of element clicked
document.forms[0].elements["fireImpairForm.bldCode"]=document.forms[0].elements[this.id].value;
});
$dialog.dialog('open');
}
</script>
and this is the HTML
<div style="display:none; visibility:hidden;">
<div id="mydialog">
<input type="hidden" id="bldCode" />
</div>
</div>
<a href="javascript:winOpenNewDlg('LookupLocation.htm','bld')">
<img src="image/search.gif" border="0"
alt="Click here to find Building"></a>
Ok rather than dig into your details let us start with a very simplified example with some comments: See and play with it here: https://jsfiddle.net/MarkSchultheiss/kkwpb5b7/
EDIT: Note how I put a click event in my code on the dialog content. This is similar to your 'click something/event of something etc) that you wish to do.
I put a simple svg icon in, yours is a gif (so we have something to click).
Markup (for my examples, yours differs a bit)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div class="data">
<form:input title="Building" styleClass="content contractorDisable" maxlength="5" size="6" path="fireImpairForm.bldCode" />
<a class='lookuplocation' data-url="LookupLocation.htm" ,data-type="bld">
<img border="0" alt="Click here to find Building">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
<circle cx="50" cy="50" r="25" stroke="black" stroke-width="5" fill="red" />
</svg>
</a>
</div>
<div style="display:none; visibility:hidden;">
<div id="mydialog">
</div>
</div>
Now see my "hidden" dialog wrapper? let's use that rather than some in-line script and then inject some content into that (you would use the src)
var $dialog ={};
$(document).ready(function()(
$dialog = $('#mydialog');
$dialog.append("<iframe id='dialogframe' style='border: 0px; width: 100%;height:100% '/>");;
$dialog.dialog({
autoOpen: false,
modal: true,
width: "auto",
height: "auto",
title: "Buildings",
buttons: [{
text: "Close Me",
click: function() {
$(this).dialog('close');
}
}]
});
});
function winOpen(urlVal, type) {
var params = '?bldCode=howdy'; // put your stuff in here
var page = urlVal + params;
// $('#dialogframe').attr('src', page);// yours would do this
// here I create a sample set of text to inject
var sample = '<div id="findem">Hi I am found</div>';
var dialogBody = $($dialog.find('#dialogframe')[0].contentWindow.document.body);
// $('#dialogframe').attr('src', page);// yours would do this
// I do this for simplicity and demonstration
dialogBody.html("<div id='original'>First Text </div>");
dialogBody.append(sample);
// add a click event to the dialog contents, you would do different things
dialogBody.on('click', '*', function() {
console.log("triggered !!");
console.log(this.id + ":" + this.innerHTML); // id of element clicked
});
$dialog.dialog('open');
}
// took this out of the markup because I don't like them there.
$('.data').on('click', 'a.lookuplocation', function() {
winOpen($(this).data('url'), $(this).data('type'));
});
I have a textbox and a plus button. When the user clicks on the plus button a new row will added with textbox and minus button, and the text area have underline like this
[ text ] +
text -
--------------------------------
So I tried something like this:
function AddNote() {
var xtbl = document.getElementById("tblMain");
var xrowcount = xtbl.rows.length;
var xrow = xtbl.insertRow(xrowcount);
var xcell0 =xrow.insertCell(0);
var xcell1 = xrow.insertCell(1);
var xcell2 = xrow.insertCell(2);
var newlabel = document.createElement("Label");
newlabel.id = "id" + xrowcount
newlabel.innerHTML = document.getElementById("txtReleaseNote").value;
xcell1.appendChild(newlabel);
var newlabel1 = document.createElement("Label");
newlabel1.id = "lblminus" + xrowcount
newlabel1.innerHTML="<h2>-</h2>"
xcell1.setAttribute("colspan", 2);
xcell1.setAttribute("borderBottom", "1px solid #0000FF");
xcell2.appendChild(newlabel1);
}
<table id="tblMain" align="center" width="100%" cellpadding="0" cellspacing="0" style="table-layout: fixed; text-align: left; margin-top:10px;">
<colgroup>
<col style="width: 50px;">
<col style="width: 145px;">
<col style="width: 350px;">
<col style="width: 100px;">
<col style="width: auto;">
<!-- Use "width: auto;" to apply the remaining (unused) space -->
<col style="width: 50px">
</colgroup>
<tbody>
<tr><td></td><td>Release Notes</td><td><asp:TextBox
id="txtReleaseNote" TextMode="MultiLine" Rows="3" runat="server" MaxLength="15"
Width= "100%" CssClass="TextBoxBorder"></asp:TextBox></td>
<td style="padding-left:15px; Color:RGB(33,88,103);"> <h2 id="lblplus"
onclick="AddNote()" style="cursor: pointer; vertical-align:text-top;" > + </h2> </td> </tr>
</tbody>
</table>
The minus button vertically not equal to the plus symbol. What am I doing wrong?
How assign color for minus symbol?
I am using asp.net 2008 CSS 2.1
This answer is explain how to fix the UI.
The open issue here is how to save it to the server because you are using ASP.NET and this framework doesn't support dynamic inputs by default. You can read the answer here http://forums.asp.net/t/1611284.aspx?How+to+get+value+from+dynamically+added+html+input+
function AddNote() {
var xtbl = document.getElementById("tblMain");
var xrowcount = xtbl.rows.length;
var xrow = xtbl.insertRow(xrowcount);
var xcell0 =xrow.insertCell(0);
var newlabel = document.createElement("Label");
newlabel.id = "id" + xrowcount
newlabel.innerHTML = document.getElementById("txtReleaseNote").value;
var xcell1 = xrow.insertCell(1);
xcell1.setAttribute("colspan", 2);
xcell1.setAttribute("style", "border-bottom:1px solid #0000FF");
xcell1.appendChild(newlabel);
var xcell2 = xrow.insertCell(2);
xcell2.setAttribute('style', 'padding-left:15px; color:RGB(33,88,103);');
var newlabel1 = document.createElement("label");
newlabel1.id = "lblminus" + xrowcount
newlabel1.innerHTML="<h2 style='cursor:pointer;margin:0;' onclick='removeRow(this)'>-</h2>"
xcell2.appendChild(newlabel1);
}
function removeRow(elm) {
var row = elm.parentNode.parentNode.parentNode;
row.parentNode.removeChild(row);
}
<table id="tblMain" align="center" width="100%" cellpadding="0" cellspacing="0" style="table-layout: fixed; text-align: left; margin-top:10px;">
<colgroup>
<col style="width: 50px;">
<col style="width: 145px;">
<col style="width: 350px;">
<col style="width: 100px;">
<col style="width: auto;">
<!-- Use "width: auto;" to apply the remaining (unused) space -->
<col style="width: 50px">
</colgroup>
<tbody>
<tr>
<td></td>
<td>Release Notes</td>
<td>
<textarea id="txtReleaseNote" rows="3" class="TextBoxBorder"></textarea>
<!-- <asp:TextBox id="txtReleaseNote" TextMode="MultiLine" Rows="3" runat="server" MaxLength="15" Width= "100%" CssClass="TextBoxBorder"></asp:TextBox>-->
</td>
<td style="padding-left:15px; color:RGB(33,88,103);">
<h2 id="lblplus" onclick="AddNote()" style="cursor: pointer; vertical-align:text-top;" > + </h2>
</td>
</tr>
</tbody>
</table>
It's work.
Html code :
<table>
<thead>
<tr>
<th>
Text
</th>
<th> <button type="button" data-bind="click: addNewRow" >
+
</button>
</th>
</tr>
</thead>
<tbody data-bind="template:{name:'tableRow', foreach: tableRows}">
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
</tr>
</tfoot>
</table>
<script id="tableRow" type="text/html">
<tr>
<td>
<input type="text" style="width:40px;" data-bind="value: number, valueUpdate: 'keyup'" />
</td>
<td>
<button type="button" data-bind="click: function(){ $data.remove(); }">
-
</button>
</td>
</tr>
</script>
knockout.js
function tableRow(number, ownerViewModel) {
this.number = ko.observable(number);
this.remove = function() {
ownerViewModel.tableRows.destroy(this);
}
}
function tableRowsViewModel() {
var that = this;
this.tableRows = ko.observableArray([]);
this.addNewRow = function() {
this.tableRows.push(new tableRow('', that));
}
this.addNewRow();
//dependentObservable to represent the last row's value
this.lastRowValue = ko.dependentObservable(function() {
var rows = that.tableRows();
return rows.length ? rows[rows.length - 1].number() : null;
});
//subscribe to changes to the last row
this.lastRowValue.subscribe(function(newValue) {
if (newValue) {
that.tableRows.push(new tableRow('', that));
}
});
}
$(document).ready(function() {
ko.applyBindings(new tableRowsViewModel());
});
For More visit this:
http://jsfiddle.net/rniemeyer/f5f8s/
SOLVED: SEE "CORRECTED SOLUTION" Area (below)
--------------------------------- ORIGINAL TEXT ---------------------------
I've created a JavaScript toaster popup to show info about an individual row. It works great in FireFox...but it goes down in flames in IE.
...suggestions and help appreciated.
WHAT I THINK IS FAILING:
I think I declared the "Toaster" class wrong and IE isn't doesn't recognize it as an array. As such, when I call "PopUp(clientId)" on the toaster it fails becuase it doesn't traverse the array.
Additionally, FireFox populates the array correctly in the documents "ready" function...but I'm not sure IE is doing so.
Lastly, since I am still new to JavaScript it (obviously) could be HOW I am creating the classes (as well).
WHERE IT FAILS:
The code fails because the value of "target" is null. This variable is null because IE doesn't seem to traverse the Toaster (array).
this.PopUp = function(clientId) {
var target = null;
jQuery.each(this, function() {
// Hide previous
if (jQuery(this)[0].IsUp)
jQuery(this)[0].PopDown();
if (jQuery(this)[0].ClientId == clientId)
target = jQuery(this)[0];
});
// Show current
target.PopUp();
}
THE FULL CODE SET:
Thanks for the help...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script src="../Includes/JavaScript/jQuery/Core/jquery-1.3.2.js" type="text/javascript"></script>
<style type="text/css">
.toast
{
width: 100%;
position: relative;
}
.toastBorder
{
width: 100%;
position: absolute;
border-radius-topright:.5em;
border-radius-topleft:.5em;
-moz-border-radius-topright:.5em;
-moz-border-radius-topleft:.5em;
-webkit-border-radius-topright:.5em;
-webkit-border-radius-topleft:.5em;
background-color: #FFFFCC;
border: 1px solid #969696;
border-bottom-color: White;
display:none;
height: 0;
bottom: 0;
}
.toastForm
{
display:none;
}
</style>
<script type="text/javascript">
// CLASS DEFINITION:
function Toast(clientId, height, speed) {
// PROPERTIES
this.IsUp = false;
this.IsDown = false;
this.ClientId = clientId;
this.Height = height;
this.Speed = speed;
// METHODS
this.PopUp = function() {
if (this.IsUp) { return; }
this.IsUp = true;
this.IsDown = false;
var speed = this.Speed;
var action = '+=' + this.Height + "px";
// Border
jQuery('#' + this.ClientId).children('div.toastBorder').fadeIn('fast', function() {
jQuery(this).animate({ height: action }, speed, function() {
// Form
jQuery(this).children('div.toastForm').fadeIn('fast');
});
});
}
this.PopDown = function() {
if (this.IsDown) { return; }
this.IsUp = false;
this.IsDown = true;
var speed = this.Speed;
var action = '-=' + this.Height + "px";
// Form
jQuery('#' + this.ClientId).children('div.toastBorder').children('div.toastForm').fadeOut('fast');
// Border
jQuery('#' + this.ClientId + ' div.toastBorder').animate({ height: action }, speed, function() {
jQuery(this).fadeOut('fast');
});
}
}
// CLASS DEFINITION:
function Toaster() {
// PROPERTIES
// METHODS
this.PopUp = function(clientId) {
var target = null;
jQuery.each(this, function() {
// Hide previous
if (jQuery(this)[0].IsUp)
jQuery(this)[0].PopDown();
if (jQuery(this)[0].ClientId == clientId)
target = jQuery(this)[0];
});
// Show current
target.PopUp();
}
this.PopDown = function(clientId) {
jQuery.each(this, function() {
if (jQuery(this)[0].ClientId == clientId)
jQuery(this)[0].PopDown(); // Hide current
});
}
this.Add = function(toast) {
var found = false;
// No duplicates are allowed
jQuery.each(this, function() {
if (jQuery(this)[0].ClientId == toast.ClientId)
found = true;
});
if (!found)
this.push(toast);
}
}
// CLASS DEFINITION: Toaster inheritance
Toaster.prototype = new Array();
var myToaster;
var myToast;
// DOM EVENT: Document.Ready()
jQuery(document).ready(function() {
if (myToaster == null)
myToaster = new Toaster();
myToaster.Add(new Toast("row1", 100, 200));
myToaster.Add(new Toast("row2", 100, 200));
myToaster.Add(new Toast("row3", 100, 200));
myToaster.Add(new Toast("row4", 100, 200));
myToaster.Add(new Toast("row5", 100, 200));
// These BOTH return true in IE...
//alert(myToaster.Items instanceof Array);
//alert(myToaster instanceof Array);
// This is for the button example
if (myToast == null)
myToast = new Toast("row3", 100, 200);
});
</script>
</head>
<body>
<br />
I need help on the following:
<ul>
<li>
This works GREAT in FireFox
</li>
<li>
IE doesn't seem to recognize the Toaster class as being an array.
</li>
</ul>
<div style="width: 300;">
<label style="display:block;color: #660000;">INDIVIDUAL pieces of toast work fine in IE:</label>
<input type="button" value="Down (row 3)" onclick="myToast.PopDown();" />
<input type="button" value="Up (row 3)" onclick="myToast.PopUp();" />
</div>
<br /><br />
<label style="color: #660000">Clicking a row IS SUPPOSED TO toggle a "piece of toast" for that row.</label>
<br /><br />
<table cellpadding="0" cellspacing="0" width="500" style=" border: solid 1px black">
<tr>
<td align="center" style="border-bottom: solid 1px black;">
Header
</td>
<td align="center" style="border-bottom: solid 1px black;">
Header
</td>
<td align="center" style="border-bottom: solid 1px black;">
Header
</td>
<td align="center" style="border-bottom: solid 1px black;">
Header
</td>
<td align="center" style="border-bottom: solid 1px black;">
Header
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3">
<div id="row1" class="toast">
<div class="toastBorder">
<div align="center" class="toastForm">
<br />
Hello
<br /><br /><br /><br /><br />
</div>
</div>
</div>
</td>
<td>
</td>
</tr>
<tr onclick="myToaster.PopUp('row1');">
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3">
<div id="row2" class="toast">
<div class="toastBorder">
<div align="center" class="toastForm">
<br />
Hello
<br /><br /><br /><br /><br />
</div>
</div>
</div>
</td>
<td>
</td>
</tr>
<tr onclick="myToaster.PopUp('row2');">
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3">
<div id="row3" class="toast">
<div class="toastBorder">
<div align="center" class="toastForm">
<br />
Hello
<br /><br /><br /><br /><br />
</div>
</div>
</div>
</td>
<td>
</td>
</tr>
<tr onclick="myToaster.PopUp('row3');">
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3">
<div id="row4" class="toast">
<div class="toastBorder">
<div align="center" class="toastForm">
<br />
Hello
<br /><br /><br /><br /><br />
</div>
</div>
</div>
</td>
<td>
</td>
</tr>
<tr onclick="myToaster.PopUp('row4');">
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3">
<div id="row5" class="toast">
<div class="toastBorder">
<div align="center" class="toastForm">
<br />
Hello
<br /><br /><br /><br /><br />
</div>
</div>
</div>
</td>
<td>
</td>
</tr>
<tr onclick="myToaster.PopUp('row5');">
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
<td align="center">
Data
</td>
</tr>
</table>
</body>
</html>
HERE IS THE CORRECTED SOLUTION:
// CLASS DEFINITION:
function Toast(clientId, maxHeight, speed) {
// PROPERTIES
this.ClientId = clientId;
this.MaxHeight = maxHeight;
this.Speed = speed;
// METHODS
this.IsUp = function() {
return (jQuery('#' + this.ClientId).children().height() > 0) ? true : false;
}
this.PopUp = function() {
if (this.IsUp()) { return; }
var speed = this.Speed;
var action = '+=' + this.MaxHeight + "px";
// Border
jQuery('#' + this.ClientId).children('div.toastBorder').fadeIn('fast', function() {
jQuery(this).animate({ height: action }, speed, function() {
// Form
jQuery(this).children('div.toastForm').fadeIn('fast');
});
});
this.IsUp(true);
}
this.PopDown = function() {
if (!this.IsUp()) { return; }
var speed = this.Speed;
var action = '-=' + this.MaxHeight + "px";
// Form
jQuery('#' + this.ClientId).children('div.toastBorder').children('div.toastForm').fadeOut('fast');
// Border
jQuery('#' + this.ClientId).children('div.toastBorder').animate({ height: action }, speed, function() {
jQuery(this).fadeOut('fast');
});
this.IsUp(false);
}
}
// CLASS DEFINITION:
function Toaster() {
// PROPERTIES
this.Items = new Array();
// METHODS
this.PopUp = function(clientId) {
var target = null;
jQuery.each(this.Items, function() {
if (jQuery(this)[0].ClientId != clientId) {
if (jQuery(this)[0].IsUp()) {
jQuery(this)[0].PopDown(); // Hide previous
}
}
if (jQuery(this)[0].ClientId == clientId) {
target = jQuery(this)[0];
}
});
if (target != null) {
if (target.IsUp() == false)
target.PopUp();
}
}
this.PopDown = function(clientId) {
jQuery.each(this.Items, function() {
if (jQuery(this)[0].ClientId == clientId)
jQuery(this)[0].PopDown(); // Hide current
});
}
this.Add = function(toast) {
var found = false;
// No duplicates are allowed
jQuery.each(this.Items, function() {
if (jQuery(this.Items)[0].ClientId == toast.ClientId)
found = true;
});
if (!found)
this.Items.push(toast);
}
}
var myToaster;
var myToast;
// DOM EVENT: Document.Ready()
$j(document).ready(function() {
if (myToaster == null)
myToaster = new Toaster();
myToaster.Add(new Toast("row1", 125, 200));
myToaster.Add(new Toast("row2", 125, 200));
myToaster.Add(new Toast("row3", 125, 200));
myToaster.Add(new Toast("row4", 125, 200));
myToaster.Add(new Toast("row5", 125, 200));
});
</script>
The attempt to "subclass" Array by using it as the prototype object for your "Toaster" class is not going to work in IE, for whatever reason. If you debug the "Add" method, you'll notice that calls to "push" don't seem to fail, but they also don't change the length of the Toaster.
Trying to make Javascript act like a nice polite object-oriented language is fraught with peril, particularly when you try and treat the native types (like Array) as if they're implemented in Javascript too.
I'd just keep an array around as part of "Toaster" someplace.