Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21331
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Suspending the flow of JS/ES execution |
| Date | 2013-09-13 13:07 -0600 |
| Message-ID | <b9h634Fc41gU1@mid.individual.net> (permalink) |
| References | (1 earlier) <4fpYt.72772$wA2.68551@fx32.iad> <b9eob3Frcm0U1@mid.individual.net> <1ddaiqhh6qdpo.1f6innudnejww.dlg@40tude.net> <b9go5nF95qcU1@mid.individual.net> <b9grpiF9udnU1@mid.individual.net> |
I wrote:
> JJ said:
>>> function somefunc() {
>>> Alert(cmsg, alertCallback);
>>> return;
>>> }
>
> In the fragment above I would like to pass an argument to the
> alertCallback() function, and in the Alert() function access thos
> arguments
>
> In one particular instance, I need to pass a scoped variable (an
> object) to the call back function.
>
> In a general situation, how do I pass one value (or an array of values)
> to this alertCallback function.
>
> Thanks for an additional kick !
I gaved myself a kick. Below is my latest ES/Js for my new Alert() function:
I welcome better code suggestions from all:
-Mel
*********** alert.js *********
var alertinit = false; // make alert box on first call only
var alertinps,nalertinps,alertdisables ;
function Alert(cmsg,callback,acallparm) {
// have an additional parm to the Alert() call:
// This acallparm is an array of 'actions' and 'objects':
// parm[0] is an action : e.g., "focus", "submit", etc
// parm[1] is an object for the action to 'work on'
var i,alertobj,capobj,msgobj,okobj ;
var inpobj,okbuttobj ;
alertinps = document.getElementsByTagName("input") ;
nalertinps = alertinps.length ;
alertdisables = [] ;
for (i=0;i<nalertinps;i++) {
inpobj = alertinps[i] ;
if (inpobj.hidden) continue ;
if (inpobj.disabled) alertdisables.push(i.toString()) ;
if (inpobj.id && inpobj.id == "ialertokbutt") continue ;
inpobj.disabled = true ;
}
if (!alertinit) { // then create the alert box
var alertdiv = document.createElement("div") ;
alertdiv.id = "ialert" ;
alertdiv.style.display = "none" ;
alertdiv.innerHTML =
'<p id="ialertcaption"></p>' +
'<p id="ialertmsg"></p>' +
'<br />' +
'<div id="ialertok">' +
'<input type="button" id="ialertokbutt" value="OK" /> ' +
'</div>'
var containobj = getobj("container") ;
containobj.appendChild(alertdiv) ;
alertinit = true; // use it from now on
}
alertobj = getobj("ialert") ;
// now set the style for the main alert box
alertobj.style.position = "absolute" ;
alertobj.style.top = "30%" ;
alertobj.style.left = "25%" ;
alertobj.style.height = "40%" ;
alertobj.style.width = "50%" ;
alertobj.style.marginTop = "0px" ;
alertobj.style.marginBottom = "0px" ;
alertobj.style.padding = "0px" ;
alertobj.style.zIndex = "1000" ;
alertobj.style.overflow = "auto" ;
alertobj.style.textAlign = "center" ;
alertobj.style.color = "black" ;
alertobj.style.background = "lightgray" ;
alertobj.style.border = "2px solid black" ;
// now set styling for the alert caption
capobj = getobj("ialertcaption") ;
capobj.style.position = "absolute" ;
capobj.style.top = "0%" ;
capobj.style.height = "12%" ;
capobj.style.marginTop = "0px" ;
capobj.style.marginBottom = "0px" ;
capobj.style.padding = "0px" ;
capobj.style.left = "0%" ;
capobj.style.width = "100%" ;
capobj.style.textAlign = "center" ;
capobj.style.fontWeight = "bolder" ;
capobj.style.textDecoration = "underline" ;
capobj.style.color = "black" ;
capobj.style.background = "yellow" ;
capobj.innerHTML = " Please Read Message Below, then Click 'OK' "
;
// now prepare and display the message
msgobj = getobj("ialertmsg") ;
msgobj.style.position = "absolute" ;
msgobj.style.top = "20%" ;
msgobj.style.left = "0%" ;
msgobj.style.width = "100%" ;
msgobj.style.marginTop = "0px" ;
msgobj.style.marginBottom = "0px";
msgobj.style.padding = "0px";
msgobj.style.textAlign = "center" ;
// re-format with <br /> replacing '~' chars, etc
cmsg = cmsg.replace(/~/g,"<br />") ;
msgobj.innerHTML = cmsg ;
// now place the 'OK' button a bit up from the bottom of my standard Alert
Box
okobj = getobj("ialertok") ;
okobj.style.position = "absolute" ;
okobj.style.bottom = "5%" ;
okobj.style.left = "45%" ;
okobj.style.width = "10%" ;
okobj.style.marginTop = "0px" ;
okobj.style.marginBottom = "0px";
okobj.style.padding = "0px";
okobj.style.textAlign = "center" ;
alertobj.style.display="block" ;
okbuttobj = getobj("ialertokbutt") ;
okbuttobj.onclick = function() {
AlertFin();
if (callback) {
// note: Check "callback" parameter here
if (acallparm) callback(acallparm) ;
else callback() ;
}
}
okbuttobj.focus() ;
}
function AlertFin() {
var i,j ;
var lexit ;
var nlendisables = alertdisables.length ;
var alertobj = getobj("ialert") ;
alertobj.style.display = "none" ;
for (i=0;i<nalertinps;i++) {
lexit = false ;
inpobj = alertinps[i] ;
if (nlendisables > 0 ) {
for (j=0;j<nlendisables;j++) {
if (alertdisables[j] === i.toString()) {
lexit = true ;
break ;
}
}
if (lexit) continue ;
}
inpobj.disabled = false ;
}
alertinps = null ;
nalertinps = 0 ;
alertdisables = null ;
return ;
}
******* end of alert.js ******
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Suspending the flow of JS/ES execution "Mel Smith" <med_cutout_syntel@aol.com> - 2013-09-12 13:53 -0600
Re: Suspending the flow of JS/ES execution Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-12 13:12 -0700
Re: Suspending the flow of JS/ES execution "Mel Smith" <med_cutout_syntel@aol.com> - 2013-09-12 15:00 -0600
Re: Suspending the flow of JS/ES execution JJ <duh@nah.meh> - 2013-09-13 04:53 +0700
Re: Suspending the flow of JS/ES execution "Mel Smith" <med_cutout_syntel@aol.com> - 2013-09-12 18:42 -0600
Re: Suspending the flow of JS/ES execution "Mel Smith" <med_cutout_syntel@aol.com> - 2013-09-13 09:09 -0600
Re: Suspending the flow of JS/ES execution "Mel Smith" <med_cutout_syntel@aol.com> - 2013-09-13 10:11 -0600
Re: Suspending the flow of JS/ES execution "Mel Smith" <med_cutout_syntel@aol.com> - 2013-09-13 13:07 -0600
csiph-web