// // pprompt.js - simple window library. // // Copyright (C) 2005 Masaki Komagata // All rights reserved. // This is free software with ABSOLUTELY NO WARRANTY. // // You can redistribute it and/or modify it under the terms of // the GNU General Public License version 2. // var PPrompt = { alert: function(type,windowName) { var options, msg ; var options = this._extend(this.getOptions(), options || {}); this.addOverlay(); /*if (navigator.appName=="Netscape") document.body.style.overflow = "hidden"; else if (navigator.appName=="Microsoft Internet Explorer") document.body.scroll = "no";*/ switch (type) { case "viande": width = 370; height = 395; nameCell = "cellViande"; break ; case "mdp": width = 300; height = 160; nameCell = "mdp_oublie"; break ; case "refuge_0": width = 370; height = 170; nameCell = "donne_croquette_refuge"; break ; case "refuge_1": width = 370; height = 170; nameCell = "donne_croquette_refuge_1"; break ; case "refuge_2": width = 370; height = 170; nameCell = "donne_croquette_refuge_2"; break ; case "refuge_3": width = 370; height = 170; nameCell = "donne_croquette_refuge_3"; break ; case "croquettes": width = 370; height = 315; nameCell = "cellCroquettes"; break ; case "jeu": width = 370; height = 250; nameCell = "cell"+windowName ; break ; case "balle": width = 370; height = 300; nameCell = "cellBalle"; break ; case "frisbee": width = 370; height = 350; nameCell = "cellFrisbee"; break ; case "baton": width = 370; height = 350; nameCell = "cellBaton"; break ; case "course": width = 370; height = 350; nameCell = "cellCourse"; break ; case "odorat": width = 370; height = 350; nameCell = "cellOdorat"; break ; case "assis": width = 370; height = 350; nameCell = "cellAssis"; break ; case "viande_sechee": width = 370; height = 350; nameCell = "cellViandeSechee"; break ; case "biscuit": width = 370; height = 350; nameCell = "cellBiscuit"; break ; case "offrir": width = 358; height = 230; nameCell = "cellOffrir"; break; case "help": width = 370; height = 250; nameCell = "cellhelp"; break ; case "prom_ville": width = 370; height = 380; nameCell = "cellVille"; break ; case "prom_campagne": width = 370; height = 460; nameCell = "cellCampagne"; break ; case "saillie": width = 370; height = 200; nameCell = "cellSaillie"; break ; case "saillie_public": width = 370; height = 250; nameCell = "cellSailliePublic"; break ; case "saillie_privee": width = 370; height = 250; nameCell = "cellSailliePrivee"; break ; case "balle_entr": width = 370; height = 280; nameCell = "cellBalleEntrainement"; break ; case "frisbee_entr": width = 370; height = 350; nameCell = "cellFrisbeeEntrainement"; break ; case "course_entr": width = 370; height = 350; nameCell = "cellCourseEntrainement"; break ; case "baton_entr": width = 370; height = 350; nameCell = "cellBatonEntrainement"; break ; case "odorat_entr": width = 370; height = 350; nameCell = "cellOdoratEntrainement"; break ; case "assis_entr": width = 370; height = 350; nameCell = "cellAssisEntrainement"; break ; case "elevage": width = 300; height = 210; nameCell = "cellElevage"; break ; case "nom": width = 300; height = 210; nameCell = "cellnom"; break ; case "defi_concours": width = 400; height = 310; nameCell = "celldefi"; break ; case "affixe": width = 300; height = 210; nameCell = "cellAffixe"; break ; case "deuil": width = 300; height = 160; nameCell = "cellDeuil"; break ; case "caresse_m": width = 370; height = 445; nameCell = "cellCaresse"; break ; case "calin_m": width = 370; height = 445; nameCell = "cellCalin"; break ; case "inscription_elevage": width = 360; height = 200; nameCell = "action_inscription"; break ; case "nouvelle_journee": width = 360; height = 350; nameCell = "nouvelle_journee"; break; case "objets_magiques": width = 360; height = 350; nameCell = "objets_magiques"; break; case "pedigree": width = 360; height = 350; nameCell = "pedigree"; break; case "capacite_detail": width = 360; height = 350; nameCell = "capacite_detail"; break; case "saillie_aide": width = 360; height = 350; nameCell = "saillie_aide"; break; case "resultat": width = 360; height = 350; nameCell = "resultat"; break; case "accessoires": width = 360; height = 350; nameCell = "accessoires"; break; case "nourriture": width = 360; height = 350; nameCell = "nourriture"; break; case "Lieu_coucher": width = 360; height = 350; nameCell = "Lieu_coucher"; break; case "jeu_aide": width = 360; height = 350; nameCell = "jeu_aide"; break; case "promenade_aide": width = 360; height = 350; nameCell = "promenade_aide"; break; case "education_canine": width = 360; height = 350; nameCell = "education_canine"; break; case "sterilisation": width = 360; height = 350; nameCell = "sterilisation"; break; case "faire_beau": width = 360; height = 350; nameCell = "faire_beau"; break; case "concours_inscrire": width = 360; height = 350; nameCell = "concours_inscrire"; break; case "specialite": width = 360; height = 350; nameCell = "specialite"; break; } var pwindow = this.getWindow(height,width); // msg var pmsg = document.createElement('div'); pmsg.className = 'pmsg'; pmsg.style.padding = '6px'; pmsg.appendChild(document.createTextNode(msg)); pwindow.appendChild(pmsg); pmsg.innerHTML = document.getElementById(nameCell).innerHTML ; // buttons /*var pbuttons = document.createElement('div'); pbuttons.id = 'pbuttons'; pbuttons.style.padding = '6px'; // ok var pbuttonOk = document.createElement('button'); pbuttonOk.className = 'pbutton'; pbuttonOk.appendChild(document.createTextNode(options.labelOk)); pbuttonOk.onclick = options.onOk; pbuttons.appendChild(pbuttonOk); pwindow.appendChild(pbuttons); */ document.body.appendChild(pwindow); //pbuttonOk.focus(); }, confirm: function(msg, options) { var options = this._extend(this.getOptions(), options || {}); this.addOverlay(); var pwindow = this.getWindow(options.height, options.width); // msg var pmsg = document.createElement('div'); pmsg.className = 'pmsg'; pmsg.style.padding = '6px'; pmsg.appendChild(document.createTextNode(msg)); pwindow.appendChild(pmsg); // buttons var pbuttons = document.createElement('div'); pbuttons.id = 'pbuttons'; pbuttons.style.padding = '6px'; // ok var pbuttonOk = document.createElement('button'); pbuttonOk.className = 'pbutton'; pbuttonOk.appendChild(document.createTextNode(options.labelOk)); pbuttonOk.onclick = options.onOk; pbuttons.appendChild(pbuttonOk); // cancel var pbuttonCancel = document.createElement('button'); pbuttonCancel.className = 'pbutton'; pbuttonCancel.appendChild(document.createTextNode(options.labelCancel)); pbuttonCancel.onclick = options.onCancel; pbuttons.appendChild(pbuttonCancel); pwindow.appendChild(pbuttons); document.body.appendChild(pwindow); pbuttonOk.focus(); }, prompt: function(msg, options) { var opt = this.getOptions(); opt.height = 100; var options = this._extend(opt, options || {}); this.addOverlay(); var pwindow = this.getWindow(options.height, options.width); // msg var pmsg = document.createElement('div'); pmsg.className = 'pmsg'; pmsg.style.padding = '6px'; pmsg.appendChild(document.createTextNode(msg)); pwindow.appendChild(pmsg); // buttons var pbuttons = document.createElement('div'); pbuttons.id = 'pbuttons'; pbuttons.style.padding = '6px'; // input var pinput = document.createElement('input'); pinput.id = 'pinput'; pinput.style.width = '260px'; pinput.setAttribute('type', 'text'); pwindow.appendChild(pinput); // ok var pbuttonOk = document.createElement('button'); pbuttonOk.className = 'pbutton'; pbuttonOk.appendChild(document.createTextNode(options.labelOk)); pbuttonOk.onclick = function() { options.onOk(pinput.value); }; pbuttons.appendChild(pbuttonOk); // cancel var pbuttonCancel = document.createElement('button'); pbuttonCancel.className = 'pbutton'; pbuttonCancel.appendChild(document.createTextNode(options.labelCancel)); pbuttonCancel.onclick = options.onCancel; pbuttons.appendChild(pbuttonCancel); pwindow.appendChild(pbuttons); document.body.appendChild(pwindow); pinput.focus(); }, addOverlay: function() { var poverlay = document.createElement('div'); poverlay.id = 'poverlay'; poverlay.style.top = '0px'; poverlay.style.left = '0px'; poverlay.style.position = 'absolute'; poverlay.style.background = '#000'; this._setOpacity(poverlay, 0.2); var pageSize = this._getPageSize(); poverlay.style.height = pageSize.pageHeight+'px'; poverlay.style.width = '100%'; document.body.appendChild(poverlay); }, removeOverlay: function() { document.body.removeChild(document.getElementById('poverlay')); }, getWindow: function(height, width) { document.body.style.padding = '0'; var pwindow = document.createElement('div'); pwindow.id = 'pwindow'; var pageSize = this._getPageSize(); var pos = this._realOffset(document.body); pwindow.style.top = (pageSize.windowHeight/2 - height/2 + pos[1])+'px'; pwindow.style.left = (pageSize.windowWidth/2 - width/2 + pos[0])+'px'; /*pwindow.style.top = _mouseY+'px'; pwindow.style.left = (_mouseX-width)+'px';*/ pwindow.style.height = height+'px'; pwindow.style.width = width+'px'; pwindow.style.position = 'absolute'; pwindow.style.backgroundColor = '#ffffcc'; pwindow.style.border = '2px solid #cdb78c'; //pwindow.style.padding = '6px'; //pwindow.style.textAlign = 'center'; return pwindow; }, close: function() { /*if (navigator.appName=="Netscape") document.body.style.overflow = "auto"; else if (navigator.appName=="Microsoft Internet Explorer") document.body.scroll = "yes";*/ this.removeOverlay(); document.body.removeChild(document.getElementById('pwindow')); }, getOptions: function() { return { 'height' : 70, 'width' : 300, 'labelOk' : 'OK', 'labelCancel' : 'Cancel', 'onOk' : function() { PPrompt.close(); }, 'onCancel' : function() { PPrompt.close(); } }; }, _extend: function(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination; }, _realOffset: function(element) { var valueT = 0, valueL = 0; do { valueT += element.scrollTop || 0; valueL += element.scrollLeft || 0; element = element.parentNode; } while (element); return [valueL, valueT]; }, _setOpacity: function(element, value){ if (typeof element == 'string') element= $(element); if (value == 1){ element.style.opacity = (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0 ; if(/MSIE/.test(navigator.userAgent) && !window.opera) element.style.filter = element.style.filter.replace(/alpha\([^\)]*\)/gi,''); } else { if(value < 0.00001) value = 0; element.style.opacity = value; if(/MSIE/.test(navigator.userAgent) && !window.opera) element.style.filter = element.style.filter.replace(/alpha\([^\)]*\)/gi,'') + 'alpha(opacity='+value*100+')'; } return element; }, _getPageSize: function() { var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, // Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } return { 'pageWidth':pageWidth, 'pageHeight':pageHeight, 'windowWidth':windowWidth, 'windowHeight':windowHeight, 'yScroll':yScroll, 'xScroll':xScroll }; } };