helper.js Generic methods
grox.js GROX-specific methods
GROX requires a place in which to build itself. This wrapper is an empty <div/> with a CSS style rule on "grox.htm" (or your own page):
CSS:
#div_modal_wrapper { display:block; }
HTML:
<div id="div_modal_wrapper"></div>
Here is GROX in action with the light background:
{
'id':'error',
'value':'@',
'text':'You must specify at least one button',
'index':-7
}
NOTE: GROX will not display a popup without
at least one button, even if the keyboard is
<script type="text/javascript">
function click_show(e) {
// Show the popup "window"
ev = resolve_event(e); // (see "helper.js" for code)
var check = GROX.check( { 'button':$('txt_button').value } ), // Validate our buttons
list = GROX.list( { 'format':'array' } ), // List all active buttons
how = {}, // Filled-in later
//
exknob;
$('txt_button').value = check; // Validated buttons
if (check.length === 0) {
alert('Please check your button selections'\n\nValid buttons are\n\n' + list);
$('txt_button').focus();
return false;
}
var how = {
'wrapper':'div_modal_wrapper', // Where the "popup" will be created
'title':$('txt_title').value, // "Window" title
'text':$('txa_message').value, // Message to display
'keyboard':$('chk_kb').checked, // "true" to accept "x || X" (abort) from keyboard
'nasty':$('chk_nasty').checked, // "true" to hide problematic HTML elements
'button':check, // e.g. "ARF" for "Abort", "Retry" and "Fail" buttons
'bg_style':$('rad_light').checked, // "true" = light background, "false" = dark background
'callback':callback // Callback method (invoked upon GROX completion)
};
// Show our popup
GROX.show(how);
return false;
}
function page_load() {
$('btn_show').onclick = click_show.bindEventListener(this);
$('txt_button').value = 'arf';
$('txa_message').value = base_text;
$('lbl_button').innerHTML = 'Buttons (' + GROX.list({ 'format':'array' }) + '):';
}
</script>
The function "page_load" is invoked when the page is rendered. This binds the "onclick" event to the "Show" button and sets the buttons and message to their default values. It also asks GROX for a list of active buttons and inserts this into the <label/> for the user's button selection.
var HESSE = (function() {
var private_property_1 = 'You cannot see this from outside HESSE';
var private_property_2 = 'HESSE shares this with you';
function private_method_1(parm) {
alert(private_property_1 + '\t\n' + arg); // Show the world one of my secrets and the passed parameter
return private_property_2; // Make private property visible (NOT public)
}
// Exposed (public) methods
return { // Bracket must be on same line to avoid JavaScript misunderstanding our intent
'public_method_1' : function(parm) { return private_method_1(parm); }
};
})();
The only method HESSE exposes is "public_method_1". It alerts a secret and returns another. This is the only interaction allowed. You cannot access any of its internal (private) properties or methods. For example:
var result = HESSE.public_method_1('arlo'); // VALID
var secret_1 = HESSE.private_property_1; // INVALID
HESSE.private_method_1('fred'); // INVALID
Let's examine GROX's "show" method.
function show_modal(how) {
// Expects
// wrapper DOM container
// title Popup title (optional)
// text Popup message
// keyboard "true" if keyboard is active
// nasty "true" to hide problematic HTML elements
// button String of button IDs
// callback Method invoked upon completion
parm = how; // Save for later
// Validate selected buttons
if (verify_options(how) === '') {
alert('You must specify at least one button');
return { 'id':'error', 'value':'@', 'text':'You must specify at least one button', 'index':-7 };
}
// Create event sinks
if (parm.keyboard) {
// Allow for "x" and/or "X" to close popup
document.onkeypress = key_press.bindEventListener(this);
}
window.onscroll = reposition.bindEventListener(this);
window.onresize = reposition.bindEventListener(this);
// Hide pesky HTML elements?
if (parm.nasty) {
show_hide_nasty('hidden');
}
// Build and show the popup "window"
var result = build_it(parm);
}
If the buttons selected do not validate, alert the Poor User and return error information to the caller.
BUTTON CLICK:
{
'id':'btn_modal_2_F',
'value':'F',
'text':'Fail',
'index':2
}
KEY PRESS:
{
'id':'keyboard',
'value':'#',
'text':String.fromCharCode(key), // text is "x" or "X"
'index':-7
}
This object is passed to a destructor method to clean up before we return to the calling page:
function hide_modal(obj) {
// Tear down the popup structure
// Un-bind button events
for (var i = 0; i < opt_btn.length; i += 1) {
$(opt_btn[i].id).onclick = '';
}
// If keyboard is active, unbind "keypress"
if (parm.keyboard) {
document.onkeypress = '';
}
// Un-bind window events
window.onscroll = '';
window.onresize = '';
// Remove modal DOM elements (close the "window")
delete_children($(parm.wrapper));
// Show pesky HTML elements?
if (parm.nasty) {
show_hide_nasty('visible');
}
return parm.callback(obj);
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented:
I found this can be very helpful for one of my requirement, but unable to edit it.
I have one web page. while accessing the webpage I require this popup to load with Accept and Decline button with dark background.
On clicking accept, it will show the page normally.
On clicking decline button it should redirect to a page to show, "plz accept the agreement to navigate the page."
Plz will you be able to help me out on this ?