From 8dfc08dbca0015f87b7a6aa68fffbae59996ca8a Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Mon, 15 Mar 2004 02:36:40 +0000 Subject: [PATCH] Change behavior of toolbar in browsers not supporting document.selection: - When the mouse is moved over the buttons the infobox shows an example text - When the user *clicks* a button, he is prompted to enter text, which is then formatted according to the button they chose and inserted into the infobox - After the first button has been clicked, the infobox no longer changes on mouse move to allow for copy and pasting. This could be modified to add an additional [+] button that pastes the content of the the infobox into the textarea, but I've tried this and found it confusing. --- includes/Skin.php | 2 +- languages/Language.php | 4 +++ stylesheets/wikibits.js | 70 +++++++++++++++++++++++++++++++---------- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/includes/Skin.php b/includes/Skin.php index 1d87bafd74..cd338b7abb 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -2377,7 +2377,7 @@ class Skin { $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n"; } - $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "');\n"; + $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "','" . addslashes(wfMsg("infobox_mozvote"))."');\n"; $toolbar.="document.writeln(\"\");\n"; return $toolbar; } diff --git a/languages/Language.php b/languages/Language.php index ddc1dd0888..c580b14a23 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -668,6 +668,10 @@ Please log in again after you receive it.", "sig_tip"=>"Your signature with timestamp", "hr_tip"=>"Horizontal line (use sparingly)", "infobox"=>"Click a button to get an example text", +# alert box shown in browsers where text selection does not work, test e.g. with mozilla or konqueror +"infobox_alert"=>"Please enter the text you want to be formatted.\\n It will be shown in the infobox for copy and pasting.\\nExample:\\n$1\\nwill become:\\n$2", +# only shown for Mozilla users +"infobox_mozvote"=>"\\nPlease vote for bug #231389 to make text selection work in Mozilla!", # Edit pages # diff --git a/stylesheets/wikibits.js b/stylesheets/wikibits.js index f4dbaa76d2..8bf119e78b 100644 --- a/stylesheets/wikibits.js +++ b/stylesheets/wikibits.js @@ -1,4 +1,7 @@ // Wikipedia JavaScript support functions +var noOverwrite=false; // if this is true, the toolbar will no longer overwrite the infobox when you move the mouse over individual items +var alertText; +var mozVote=""; // Un-trap us from framesets if( window.top != window ) window.top.location = window.location; @@ -43,7 +46,7 @@ function fetchTimezone() { var tzRaw = localclock.getTimezoneOffset(); var tzHour = Math.floor( Math.abs(tzRaw) / 60); var tzMin = Math.abs(tzRaw) % 60; - var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + + var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + ":" + ((tzMin < 10) ? "0" : "") + tzMin; return tzString; } @@ -83,27 +86,49 @@ function toggleToc() { // we use it to avoid creating the toolbar where javascript is not enabled function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) { - speedTip=escapeQuotes(speedTip); tagOpen=escapeQuotes(tagOpen); tagClose=escapeQuotes(tagClose); sampleText=escapeQuotes(sampleText); + var mouseOver=""; + + // we can't change the selection, so we show example texts + // when moving the mouse instead, until the first button is clicked + if(!document.selection) { + // filter backslashes so it can be shown in the infobox + var re=new RegExp("\\\\n","g"); + tagOpen=tagOpen.replace(re,""); + tagClose=tagClose.replace(re,""); + mouseOver = "onMouseover=\"if(!noOverwrite){document.infoform.infobox.value='"+tagOpen+sampleText+tagClose+"'};\""; + } + document.write(""); - document.write("\""+speedTip+"\""); + + document.write("\""+speedTip+"\""); document.write(""); return; } -function addInfobox(infoText) { +function addInfobox(infoText,text_alert,text_moz) { + alertText=text_alert; + var clientPC = navigator.userAgent.toLowerCase(); // Get client info + if(clientPC.indexOf('gecko')!=-1) { mozVote=text_moz; } + + var re=new RegExp("\\\\n","g"); + alertText=alertText.replace(re,"\n"); + mozVote=mozVote.replace(re,"\n"); // if no support for changing selection, add a small copy & paste field var clientPC = navigator.userAgent.toLowerCase(); // Get client info - var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1) + /*var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1) && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1) && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1) - && (clientPC.indexOf('khtml')==-1) && (clientPC.indexOf('gecko')==-1)); - if(!document.selection && !is_nav) { + && (clientPC.indexOf('khtml')==-1));*/ + + // document.selection is an IE property. If it is not available, we generates + // an infobox used by the toolbar in other browsers. + if(!document.selection) { infoText=escapeQuotesHTML(infoText); document.write("
"+ "