[Phpfreechat-svn] SF.net SVN: phpfreechat: [965] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2007-02-18 21:23:14
|
Revision: 965 http://svn.sourceforge.net/phpfreechat/?rev=965&view=rev Author: kerphi Date: 2007-02-18 13:23:11 -0800 (Sun, 18 Feb 2007) Log Message: ----------- [en] Replace default prompt() javascript function by a DHTML popup to fix IE7 problems [5h15] [fr] Remplace la fonction prompt() de javascript par un popup DHTML pour r?\195?\169soudre les probl?\195?\168mes IE7 [5h15] Modified Paths: -------------- trunk/data/public/js/pfcclient.js trunk/themes/default/chat.js.tpl.php trunk/themes/default/style.css.php Added Paths: ----------- trunk/data/public/js/pfcprompt.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-02-16 20:49:27 UTC (rev 964) +++ trunk/data/public/js/pfcclient.js 2007-02-18 21:23:11 UTC (rev 965) @@ -1,7 +1,7 @@ -var is_ie = navigator.appName.match("Explorer"); +var is_ie = navigator.appName.match("Explorer"); var is_khtml = navigator.appName.match("Konqueror") || navigator.appVersion.match("KHTML"); -var is_ff = navigator.appName.match("Netscape"); - +var is_ff = navigator.appName.match("Netscape"); +var is_ie7 = navigator.userAgent.indexOf('MSIE 7') > 0; /** * This class is the client part of phpFreeChat * (depends on prototype library) @@ -57,7 +57,7 @@ this.blinktmp = Array(); this.blinkloop = Array(); - this.blinktimeout = Array(); + this.blinktimeout = Array(); }, connectListener: function() @@ -137,12 +137,20 @@ askNick: function(nickname) { // ask to choose a nickname - if (nickname == '') nickname = this.nickname; - var newnick = prompt(this.res.getLabel('Please enter your nickname'), nickname); + if (nickname == '' || nickname == undefined) nickname = this.nickname; + + // build a dhtml prompt box + var pfcp = this.getPrompt();//new pfcPrompt($('pfc_container')); + pfcp.callback = function(v) { pfc.askNickResponse(v); } + pfcp.prompt(this.res.getLabel('Please enter your nickname'), nickname); + pfcp.focus(); + }, + askNickResponse: function(newnick) + { if (newnick) this.sendRequest('/nick "'+newnick+'"'); }, - + /** * Reacte to the server response */ @@ -171,9 +179,6 @@ this.sendRequest('/nick "'+this.nickname+'"'); } - // give focus the the input text box if wanted - if (pfc_focus_on_connect) this.el_words.focus(); - this.isconnected = true; // start the polling system @@ -268,6 +273,9 @@ } else if (cmd == "nick") { + // give focus the the input text box if wanted + if (pfc_focus_on_connect) this.el_words.focus(); + if (resp == "connected" || resp == "notchanged") { cmd = ''; @@ -339,7 +347,6 @@ this.isconnected = false; this.refresh_loginlogout(); } - } else if (cmd == "update") { @@ -1536,7 +1543,14 @@ insert_text: function(open, close, promptifselempty) { var msgfield = $('pfc_words'); - + + var pfcp = this.getPrompt(); + pfcp.msgfield = msgfield; + pfcp.open = open; + pfcp.close = close; + pfcp.promptifselempty = promptifselempty; + pfcp.callback = this.insert_text_callback; + // IE support if (document.selection && document.selection.createRange) { @@ -1544,7 +1558,51 @@ sel = document.selection.createRange(); var text = sel.text; if (text == "" && promptifselempty) - text = prompt(this.res.getLabel('Enter the text to format'),''); + { + pfcp.sel = document.selection.createRange(); + pfcp.prompt(this.res.getLabel('Enter the text to format'), ''); + pfcp.focus(); + } + else + this.insert_text_callback(text,pfcp); + } + + // Mozilla support + else if (msgfield.selectionStart || msgfield.selectionStart == '0') + { + var startPos = msgfield.selectionStart; + var endPos = msgfield.selectionEnd; + + var text = msgfield.value.substring(startPos, endPos); + var extralength = 0; + if (startPos == endPos && promptifselempty) + { + pfcp.prompt(this.res.getLabel('Enter the text to format'), ''); + pfcp.focus(); + } + else + this.insert_text_callback(text,pfcp); + } + + // Fallback support for other browsers + else + { + pfcp.prompt(this.res.getLabel('Enter the text to format'), ''); + pfcp.focus(); + } + return; + }, + insert_text_callback: function(text,pfcp) + { + var open = pfcp.open; + var close = pfcp.close; + var promptifselempty = pfcp.promptifselempty; + var msgfield = pfcp.msgfield; + var sel = pfcp.sel; + + // IE support + if (document.selection && document.selection.createRange) + { if (text == null) text = ""; if (text.length > 0 || !promptifselempty) { @@ -1553,18 +1611,15 @@ msgfield.focus(); } } - - // Moz support + // Mozilla support else if (msgfield.selectionStart || msgfield.selectionStart == '0') { var startPos = msgfield.selectionStart; - var endPos = msgfield.selectionEnd; + var endPos = msgfield.selectionEnd; - var text = msgfield.value.substring(startPos, endPos); var extralength = 0; if (startPos == endPos && promptifselempty) { - text = prompt(this.res.getLabel('Enter the text to format'),''); if (text == null) text = ""; extralength = text.length; } @@ -1575,11 +1630,9 @@ msgfield.focus(); } } - // Fallback support for other browsers else { - var text = prompt(this.res.getLabel('Enter the text to format'),''); if (text == null) text = ""; if (text.length > 0 || !promptifselempty) { @@ -1587,7 +1640,6 @@ msgfield.focus(); } } - return; }, /** @@ -1749,5 +1801,12 @@ chatdiv.style.width = ''; } } + }, + + getPrompt: function() + { + if (!this.pfc) + this.pfc = new pfcPrompt($('pfc_container')); + return this.pfc; } }; Added: trunk/data/public/js/pfcprompt.js =================================================================== --- trunk/data/public/js/pfcprompt.js (rev 0) +++ trunk/data/public/js/pfcprompt.js 2007-02-18 21:23:11 UTC (rev 965) @@ -0,0 +1,136 @@ +// DHTML prompt() function replacement inspirated by : +// http://www.hunlock.com/blogs/Working_around_IE7s_prompt_bug,_er_feature + +var pfcPrompt = Class.create(); +pfcPrompt.prototype = { + initialize: function(container) + { + if (container == undefined || is_ie) + container = document.getElementsByTagName('body')[0]; + this.container = container; + this.box = $('pfc_promptbox'); + this.bgbox = $('pfc_promptbgbox'); + this.prompt_field = $('pfc_promptbox_field'); + this.prompt_title = $('pfc_promptbox_title'); + + this.buildBox(); + this.buildBgBox(); + }, + + buildBox: function() + { + if (!this.box) + { + this.box = document.createElement('div'); + this.box.id = 'pfc_promptbox'; + this.box.style.position = 'absolute'; + this.box.style.width = '330px'; + this.box.style.zIndex = '100'; + this.box.style.display = 'none'; + + var div = document.createElement('h2'); + div.appendChild(document.createTextNode('Input Required')); + this.box.appendChild(div); + + this.prompt_title = document.createElement('p'); + this.prompt_title.id = 'pfc_promptbox_title'; + this.box.appendChild(this.prompt_title); + + var form = document.createElement('form'); + form.pfc_prompt = this; + form.onsubmit = function(evt) { return this.pfc_prompt._doSubmit(); }; + this.box.appendChild(form); + + this.prompt_field = document.createElement('input'); + this.prompt_field.id = 'pfc_promptbox_field'; + this.prompt_field.type = 'text'; + this.prompt_field.value = ''; + form.appendChild(this.prompt_field); + + var br = document.createElement('br'); + form.appendChild(br); + + var submit = document.createElement('input'); + submit.id = 'pfc_promptbox_submit'; + submit.type = 'submit'; + submit.value = 'OK'; + form.appendChild(submit); + + var cancel = document.createElement('input'); + cancel.id = 'pfc_promptbox_cancel'; + cancel.type = 'button'; + cancel.value = 'Cancel'; + cancel.pfc_prompt = this; + cancel.onclick = function(evt) { return this.pfc_prompt._doSubmit(true); }; + form.appendChild(cancel); + + this.container.appendChild(this.box); + } + }, + + buildBgBox: function() + { + if (!this.bgbox) + { + this.bgbox = document.createElement('div'); + this.bgbox.id = 'pfc_promptbgbox'; + // assign the styles to the blackout division. + this.bgbox.style.opacity = '.7'; + this.bgbox.style.position = 'absolute'; +// this.bgbox.style.top = '0px'; +// this.bgbox.style.left = '0px'; + this.bgbox.style.backgroundColor = '#555'; + this.bgbox.style.filter = 'alpha(opacity=70)'; +// this.bgbox.style.height = (document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; + this.bgbox.style.display = 'none'; + this.bgbox.style.zIndex = '50'; + this.container.appendChild(this.bgbox); + } + }, + + prompt: function(text,def) + { + // if def wasn't actually passed, initialize it to null + if (def==undefined) { def=''; } + + // Stretch the blackout division to fill the entire document + // and make it visible. Because it has a high z-index it should + // make all other elements on the page unclickable. + this.bgbox.style.top = (this.container.offsetTop-8)+'px'; // -8 because strange margin when the container is not 'body' + this.bgbox.style.left = this.container.offsetLeft+'px'; + this.bgbox.style.height = this.container.offsetHeight+'px'; + this.bgbox.style.width = this.container.offsetWidth+'px'; + this.bgbox.style.display = 'block'; + + // Position the dialog box on the screen and make it visible. + this.box.style.top = parseInt(this.container.offsetTop+(this.container.offsetHeight-200)/2)+'px'; + this.box.style.left = parseInt(this.container.offsetLeft+(this.container.offsetWidth-315)/2)+'px'; + this.box.style.display = 'block'; + this.prompt_field.value = def; + this.prompt_field.focus(); // Give the dialog box's input field the focus. + this.prompt_title.innerHTML = text; + }, + + _doSubmit: function(canceled) + { + // _doSubmit is called when the user enters or cancels the box. + var val = this.prompt_field.value; + this.box.style.display = 'none'; // clear out the dialog box + this.bgbox.style.display = 'none'; // clear out the screen + this.prompt_field.value = ''; // clear out the text field + // if the cancel button was pushed, force value to null. + if (canceled) { val = '' } + // call the user's function + this.callback(val,this); + return false; + }, + + focus: function() + { + this.prompt_field.focus(); + }, + + callback: function(v,pfcp) + { + } +} \ No newline at end of file Modified: trunk/themes/default/chat.js.tpl.php =================================================================== --- trunk/themes/default/chat.js.tpl.php 2007-02-16 20:49:27 UTC (rev 964) +++ trunk/themes/default/chat.js.tpl.php 2007-02-18 21:23:11 UTC (rev 965) @@ -123,6 +123,7 @@ <script type="text/javascript" src="<?php echo $c->data_public_url; ?>/js/pfcclient.js"></script> <script type="text/javascript" src="<?php echo $c->data_public_url; ?>/js/pfcgui.js"></script> <script type="text/javascript" src="<?php echo $c->data_public_url; ?>/js/pfcresource.js"></script> +<script type="text/javascript" src="<?php echo $c->data_public_url; ?>/js/pfcprompt.js"></script> <div id="pfc_notloading" style="width:270px;background-color:#FFF;color:#000;border:1px solid #000;text-align:center;margin:5px auto 0 auto;font-size:10px;background-image:url('http://img402.imageshack.us/img402/3766/stopcc3.gif');background-repeat:no-repeat;background-position:center center;"> Modified: trunk/themes/default/style.css.php =================================================================== --- trunk/themes/default/style.css.php 2007-02-16 20:49:27 UTC (rev 964) +++ trunk/themes/default/style.css.php 2007-02-18 21:23:11 UTC (rev 965) @@ -396,3 +396,39 @@ height: 0; } + +/* The DHTML prompt */ +div#pfc_promptbox { + /* color:red;*/ + border: 2px solid #000; + background-color: #DDD; +} +div#pfc_promptbox h2 { + margin: 0; + width: 100%; + background-color: #888; + color: white; + font-family: verdana; + font-size: 10pt; + font-weight: bold; + height: 20px; +} +div#pfc_promptbox p { + margin: 10px 0 0 10px; +} +div#pfc_promptbox form { + margin: 0 10px 10px 10px; + text-align: right; +} +div#pfc_promptbox input { + border: 1px solid #000; +} +input#pfc_promptbox_field { + width: 100%; +} +input#pfc_promptbox_submit { + margin: 5px 10px 0 0; +} +input#pfc_promptbox_cancel { + margin: 0; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |