Thread: [Phpfreechat-svn] SF.net SVN: phpfreechat: [1120] trunk/data/public/js/pfcclient.js (Page 2)
Status: Beta
Brought to you by:
kerphi
From: <gpi...@us...> - 2007-08-14 17:05:13
|
Revision: 1120 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1120&view=rev Author: gpinzone Date: 2007-08-14 10:05:15 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Attempt to implement IE selection tracking code to insert_text. Does not seem to retain last known caret/selection positions. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-13 17:08:34 UTC (rev 1119) +++ trunk/data/public/js/pfcclient.js 2007-08-14 17:05:15 UTC (rev 1120) @@ -1708,7 +1708,15 @@ if (document.selection && document.selection.createRange) { msgfield.focus(); - pfcp.sel = document.selection.createRange(); + + // Set range based on stored values. + var range = msgfield.createTextRange(); + range.collapse(true); + range.moveStart("character", msgfield.selStart); + range.moveEnd("character", msgfield.selEnd - msgfield.selStart); + range.select(); + + pfcp.sel = range; var text = pfcp.sel.text; if (text == "" && promptifselempty) { @@ -1757,9 +1765,13 @@ if (text == null) text = ""; if (text.length > 0 || !promptifselempty) { + msgfield.focus(); sel.text = open + text + close; // @todo move the cursor just after the BBCODE, this doesn't work when the text to enclose is selected, IE6 keeps the whole selection active after the operation. - msgfield.focus(); + // Increment caret position. + // Check if internally kept values for selection are initialized. + msgfield.selStart = (msgfield.selStart) ? msgfield.selStart + sel.text.length : sel.text.length; + msgfield.selEnd = msgfield.selStart; } } // Mozilla support This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-14 20:55:19
|
Revision: 1121 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1121&view=rev Author: gpinzone Date: 2007-08-14 13:55:19 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Successfully merged insertSmiley caret/selection for IE enhancements to insert_text. Moved IE selection enhancements to separate functions. Moved check for Gecko first in insert_text to prevent problems with Opera. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-14 17:05:15 UTC (rev 1120) +++ trunk/data/public/js/pfcclient.js 2007-08-14 20:55:19 UTC (rev 1121) @@ -784,18 +784,21 @@ }, callbackWords_OnKeyup: function(evt) { - // Needed for IE since the text box loses caret position on blur - this.storeSelectionPos(); + // Needed for IE since the text box loses selection/caret position on blur + this.storeSelectionPos(this.el_words); }, callbackWords_OnMouseup: function(evt) { - // Needed for IE since the text box loses caret position on blur - this.storeSelectionPos(); + // Needed for IE since the text box loses selection/caret position on blur + this.storeSelectionPos(this.el_words); }, callbackWords_OnFocus: function(evt) { // if (this.el_handle && this.el_handle.value == '' && !this.minmax_status) // this.el_handle.focus(); + + // Needed for IE since the text box loses selection/caret position on blur + this.setSelectionIE(this.el_words); }, callbackHandle_OnKeydown: function(evt) { @@ -1039,35 +1042,57 @@ }, /** - * Stores the caret position for IE 6.x and 7.x + * Stores the caret/selection position for IE 6.x and 7.x * Code based on: http://www.bazon.net/mishoo/articles.epl?art_id=1292 */ - storeSelectionPos: function() + storeSelectionPos: function(obj) { - var w = this.el_words; - + // Exit function if browser supports Gecko selection model + if (obj.setSelectionRange) return false; + // IE - if (w.createTextRange && document.selection) + if (obj.createTextRange && document.selection) { // Determine current selection start position. var range = document.selection.createRange(); var isCollapsed = range.compareEndPoints("StartToEnd", range) == 0; if (!isCollapsed) range.collapse(true); - var b = range.getBookmark(); - w.selStart = b.charCodeAt(2) - b.charCodeAt(0) - 1; - + var b = range.getBookmark(); + obj.selStart = b.charCodeAt(2) - b.charCodeAt(0) - 1; + // Determine current selection end position. range = document.selection.createRange(); - isCollapsed = range.compareEndPoints("StartToEnd", range) == 0; + isCollapsed = range.compareEndPoints("StartToEnd", range) == 0; if (!isCollapsed) range.collapse(false); b = range.getBookmark(); - w.selEnd = b.charCodeAt(2) - b.charCodeAt(0) - 1; + obj.selEnd = b.charCodeAt(2) - b.charCodeAt(0) - 1; + + return true; } }, /** + * Sets the selection/caret in the object based on the object's selStart and selEnd parameters. + * This is for IE 6.x and 7.x only. + */ + setSelectionIE: function(obj) + { + // IE - Don't process if browser supports Gecko selection model + if (obj.createTextRange && !obj.setSelectionRange) + { + var range = obj.createTextRange(); + range.collapse(true); + range.moveStart("character", obj.selStart); + range.moveEnd("character", obj.selEnd - obj.selStart); + range.select(); + + return range; + } + }, + + /** * insert a smiley */ insertSmiley: function(smiley) @@ -1088,11 +1113,7 @@ w.focus(); // Set range based on stored values. - var range = w.createTextRange(); - range.collapse(true); - range.moveStart("character", w.selStart); - range.moveEnd("character", w.selEnd - w.selStart); - range.select(); + var range = this.setSelectionIE(w); //document.selection.createRange().text = smiley; range.text = smiley; @@ -1689,6 +1710,7 @@ content.style.display = 'block'; } }, + /** * BBcode ToolBar @@ -1704,21 +1726,15 @@ pfcp.promptifselempty = promptifselempty; pfcp.callback = this.insert_text_callback; - // IE support - if (document.selection && document.selection.createRange) + // Mozilla support + if (msgfield.selectionStart || msgfield.selectionStart == '0') { - msgfield.focus(); + var startPos = msgfield.selectionStart; + var endPos = msgfield.selectionEnd; - // Set range based on stored values. - var range = msgfield.createTextRange(); - range.collapse(true); - range.moveStart("character", msgfield.selStart); - range.moveEnd("character", msgfield.selEnd - msgfield.selStart); - range.select(); - - pfcp.sel = range; - var text = pfcp.sel.text; - if (text == "" && promptifselempty) + 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(); @@ -1727,15 +1743,15 @@ this.insert_text_callback(text,pfcp); } - // Mozilla support - else if (msgfield.selectionStart || msgfield.selectionStart == '0') + // IE support + else if (document.selection && document.selection.createRange) { - var startPos = msgfield.selectionStart; - var endPos = msgfield.selectionEnd; + msgfield.focus(); - var text = msgfield.value.substring(startPos, endPos); - var extralength = 0; - if (startPos == endPos && promptifselempty) + // Set range based on stored values. + pfcp.range = this.setSelectionIE(msgfield); + var text = pfcp.range.text; + if (text == "" && promptifselempty) { pfcp.prompt(this.res.getLabel('Enter the text to format'), ''); pfcp.focus(); @@ -1758,24 +1774,10 @@ 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) - { - msgfield.focus(); - sel.text = open + text + close; - // @todo move the cursor just after the BBCODE, this doesn't work when the text to enclose is selected, IE6 keeps the whole selection active after the operation. - // Increment caret position. - // Check if internally kept values for selection are initialized. - msgfield.selStart = (msgfield.selStart) ? msgfield.selStart + sel.text.length : sel.text.length; - msgfield.selEnd = msgfield.selStart; - } - } + var range = pfcp.range; + // Mozilla support - else if (msgfield.selectionStart || msgfield.selectionStart == '0') + if (msgfield.selectionStart || msgfield.selectionStart == '0') { var startPos = msgfield.selectionStart; var endPos = msgfield.selectionEnd; @@ -1789,10 +1791,29 @@ if (text.length > 0 || !promptifselempty) { msgfield.value = msgfield.value.substring(0, startPos) + open + text + close + msgfield.value.substring(endPos, msgfield.value.length); - msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + extralength + close.length; + var caretPos = endPos + open.length + extralength + close.length; + msgfield.setSelectionRange(caretPos, caretPos); msgfield.focus(); } } + // IE support + else if (document.selection && document.selection.createRange) + { + if (text == null) text = ""; + if (text.length > 0 || !promptifselempty) + { + msgfield.focus(); + + range.text = open + text + close; + + // Increment caret position. + // Check if internally kept values for selection are initialized. + msgfield.selStart = (msgfield.selStart) ? msgfield.selStart + open.length + text.length + close.length : open.length + text.length + close.length; + msgfield.selEnd = msgfield.selStart; + + msgfield.focus(); + } + } // Fallback support for other browsers else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-15 00:23:10
|
Revision: 1122 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1122&view=rev Author: gpinzone Date: 2007-08-14 17:23:11 -0700 (Tue, 14 Aug 2007) Log Message: ----------- Various cleanups and documentation updates. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-14 20:55:19 UTC (rev 1121) +++ trunk/data/public/js/pfcclient.js 2007-08-15 00:23:11 UTC (rev 1122) @@ -798,7 +798,7 @@ // this.el_handle.focus(); // Needed for IE since the text box loses selection/caret position on blur - this.setSelectionIE(this.el_words); + this.setSelection(this.el_words); }, callbackHandle_OnKeydown: function(evt) { @@ -1043,15 +1043,25 @@ /** * Stores the caret/selection position for IE 6.x and 7.x + * Returns true if text range start and end values were updated. * Code based on: http://www.bazon.net/mishoo/articles.epl?art_id=1292 */ storeSelectionPos: function(obj) { - // Exit function if browser supports Gecko selection model - if (obj.setSelectionRange) return false; - + // We don't need to store the start and end positions if the browser + // supports the Gecko selection model. However, these values may be + // useful for debugging. Also, Opera recognizes Gecko and IE range + // commands, so we need to ensure Opera only uses the Gecko model. + if (obj.setSelectionRange) + { + obj.selStart = obj.selectionStart; + obj.selEnd = obj.selectionEnd; + + return true; + } + // IE - if (obj.createTextRange && document.selection) + else if (obj.createTextRange && document.selection) { // Determine current selection start position. var range = document.selection.createRange(); @@ -1071,17 +1081,32 @@ return true; } + + // Browser does not support selection range processing. + else + return false; }, /** - * Sets the selection/caret in the object based on the object's selStart and selEnd parameters. - * This is for IE 6.x and 7.x only. + * Sets the selection/caret in the object based on the + * object's selStart and selEnd parameters. + * This should only be needed for IE only. */ - setSelectionIE: function(obj) + setSelection: function(obj) { - // IE - Don't process if browser supports Gecko selection model - if (obj.createTextRange && !obj.setSelectionRange) + // This part of the function is included to prevent + // Opera from executing the IE portion. + /* WARNING: Do not attempt to use this function as + a wrapper for the Gekco based setSelectionRange. + It causes problems in Opera when executed from + the event trigger onFocus. */ + if (obj.setSelectionRange) { + return null; + } + // IE + else if (obj.createTextRange) + { var range = obj.createTextRange(); range.collapse(true); range.moveStart("character", obj.selStart); @@ -1090,16 +1115,21 @@ return range; } + // Browser does not support selection range processing. + else + return null; }, /** * insert a smiley + * TODO: Merge functionality into "insert_text" function and eliminate. */ insertSmiley: function(smiley) { var w = this.el_words; - if (w.setSelectionRange) { + if (w.setSelectionRange) + { // Gecko var s = w.selectionStart; var e = w.selectionEnd; @@ -1112,13 +1142,12 @@ // IE w.focus(); - // Set range based on stored values. - var range = this.setSelectionIE(w); + // Get range based on stored values. + var range = this.setSelection(w); - //document.selection.createRange().text = smiley; range.text = smiley; - // Increment caret position. + // Move caret position to end of smiley and collapse selection, if any. // Check if internally kept values for selection are initialized. w.selStart = (w.selStart) ? w.selStart + smiley.length : smiley.length; w.selEnd = w.selStart; @@ -1677,7 +1706,6 @@ }, - /** * Minimize/Maximized the chat zone */ @@ -1726,30 +1754,31 @@ pfcp.promptifselempty = promptifselempty; pfcp.callback = this.insert_text_callback; - // Mozilla support + // Gecko + /* Always check for Gecko selection processing commands + first. This is needed for Opera. */ 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); + this.insert_text_callback(text, pfcp); } - // IE support + // IE else if (document.selection && document.selection.createRange) { msgfield.focus(); - // Set range based on stored values. - pfcp.range = this.setSelectionIE(msgfield); + // Get selection range. + pfcp.range = this.setSelection(msgfield); var text = pfcp.range.text; if (text == "" && promptifselempty) { @@ -1757,7 +1786,7 @@ pfcp.focus(); } else - this.insert_text_callback(text,pfcp); + this.insert_text_callback(text, pfcp); } // Fallback support for other browsers @@ -1768,7 +1797,7 @@ } return; }, - insert_text_callback: function(text,pfcp) + insert_text_callback: function(text, pfcp) { var open = pfcp.open; var close = pfcp.close; @@ -1776,7 +1805,9 @@ var msgfield = pfcp.msgfield; var range = pfcp.range; - // Mozilla support + // Gecko + /* Always check for Gecko selection processing commands + first. This is needed for Opera. */ if (msgfield.selectionStart || msgfield.selectionStart == '0') { var startPos = msgfield.selectionStart; @@ -1796,7 +1827,7 @@ msgfield.focus(); } } - // IE support + // IE else if (document.selection && document.selection.createRange) { if (text == null) text = ""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-15 19:36:06
|
Revision: 1125 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1125&view=rev Author: gpinzone Date: 2007-08-15 12:35:55 -0700 (Wed, 15 Aug 2007) Log Message: ----------- Modified nickname completion to work anywhere within a string rather than only working at the end. Uses caret/selection position. Need to test on non-compliant browser like older Konqueror. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-15 03:57:47 UTC (rev 1124) +++ trunk/data/public/js/pfcclient.js 2007-08-15 19:35:55 UTC (rev 1125) @@ -604,10 +604,30 @@ completeNick: function() { var w = this.el_words; - var last_space = w.value.lastIndexOf(' '); - var nick_src = w.value.substring(last_space+1, w.value.length); - var non_nick_src = w.value.substring(0, last_space+1); + var selStart = w.value.length; // Default for browsers that don't support selection/caret position commands. + var selEnd = selStart; + // Get selection/caret position. + if (w.setSelectionRange) + { + // We don't rely on the stored values for browsers that support + // the selectionStart and selectionEnd commands. + selStart = w.selectionStart; + selEnd = w.selectionEnd; + } + else if (w.createTextRange && document.selection) + { + // We must rely on the stored values for IE browsers. + selStart = (w.selStart != null) ? w.selStart : w.value.length; + selEnd = (w.selEnd != null) ? w.selEnd : w.value.length; + } + + var begin = w.value.lastIndexOf(' ', selStart - 1) + 1; + var end = (w.value.indexOf(' ', selStart) >= 0) ? w.value.indexOf(' ', selStart) : w.value.length; + var nick_src = w.value.substring(begin, end); + var non_nick_begin = w.value.substring(0, begin); + var non_nick_end = w.value.substring(end, w.value.length); + if (nick_src != '') { var tabid = this.gui.getTabId(); @@ -641,15 +661,14 @@ } if (nick_match) { - w.value = non_nick_src + nick_src.replace(nick_src, nick_replace); - // Move cursor to end of line. - // This fixes Webkit (Safari) and hopefully newer Konqueror releases. - /* Konqueror does not support setSelectionRange() on KDE versions <3.5.2. */ + w.value = non_nick_begin + nick_src.replace(nick_src, nick_replace) + non_nick_end; + w.selStart = w.selEnd = non_nick_begin.length + nick_replace.length; + + // Move cursor to end of completed nick. if (w.setSelectionRange) - { - var selEnd = w.value.length; - w.setSelectionRange(selEnd, selEnd); - } + w.setSelectionRange(w.selEnd, w.selEnd); // Gecko + else + this.setSelection(w); // IE } } }, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-21 01:46:07
|
Revision: 1137 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1137&view=rev Author: gpinzone Date: 2007-08-20 18:46:09 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Fix for parse smileys: No longer replace smileys inside of HTML tags. Tested on Firefox only. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-20 21:22:57 UTC (rev 1136) +++ trunk/data/public/js/pfcclient.js 2007-08-21 01:46:09 UTC (rev 1137) @@ -1458,8 +1458,11 @@ var sl = smileys.keys(); for(var i = 0; i < sl.length; i++) { - rx = new RegExp(RegExp.escape(sl[i]),'g'); - msg = msg.replace(rx, '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'); + // Emulate negative lookbehind in JavaScript. + // We don't want to replace smiley strings inside of tags. + // See http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript for more info. + rx = new RegExp('(<[^>]*)?' + RegExp.escape(sl[i]),'g'); + msg = msg.replace(rx, function($0, $1){ return $1 ? $0 : $1 + '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'; }); } // try to parse nickname for highlighting This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-21 02:16:15
|
Revision: 1138 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1138&view=rev Author: gpinzone Date: 2007-08-20 19:16:16 -0700 (Mon, 20 Aug 2007) Log Message: ----------- Fixed new regex for smileys. Phew! Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-21 01:46:09 UTC (rev 1137) +++ trunk/data/public/js/pfcclient.js 2007-08-21 02:16:16 UTC (rev 1138) @@ -1461,8 +1461,8 @@ // Emulate negative lookbehind in JavaScript. // We don't want to replace smiley strings inside of tags. // See http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript for more info. - rx = new RegExp('(<[^>]*)?' + RegExp.escape(sl[i]),'g'); - msg = msg.replace(rx, function($0, $1){ return $1 ? $0 : $1 + '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'; }); + rx = new RegExp("(<[^>]*)?" + RegExp.escape(sl[i]),'g'); + msg = msg.replace(rx, function($0, $1){ return $1 ? $0 : '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'; }); } // try to parse nickname for highlighting This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-23 19:40:14
|
Revision: 1141 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1141&view=rev Author: gpinzone Date: 2007-08-23 12:40:15 -0700 (Thu, 23 Aug 2007) Log Message: ----------- Revised smiley bugfix to use negative lookahead since it's natively supported in JavaScript. Sort smiley keys by length (longest to shortest) to prevent shorter smileys from taking precedence over longer ones. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-22 06:38:33 UTC (rev 1140) +++ trunk/data/public/js/pfcclient.js 2007-08-23 19:40:15 UTC (rev 1141) @@ -1455,14 +1455,14 @@ // try to parse smileys var smileys = this.res.getSmileyHash(); - var sl = smileys.keys(); + // Sort keys by longest to shortest. This prevents a smiley like :) from being used on >:) + var sl = smileys.keys().sort(function (a,b){return (b.unescapeHTML().length - a.unescapeHTML().length);}); for(var i = 0; i < sl.length; i++) { - // Emulate negative lookbehind in JavaScript. // We don't want to replace smiley strings inside of tags. - // See http://blog.stevenlevithan.com/archives/mimic-lookbehind-javascript for more info. - rx = new RegExp("(<[^>]*)?" + RegExp.escape(sl[i]),'g'); - msg = msg.replace(rx, function($0, $1){ return $1 ? $0 : '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'; }); + // Use negative lookahead to search for end of tag. + rx = new RegExp(RegExp.escape(sl[i]) + "(?![^<]*>)",'g'); + msg = msg.replace(rx, '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'); } // try to parse nickname for highlighting This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-27 14:21:00
|
Revision: 1148 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1148&view=rev Author: gpinzone Date: 2007-08-27 07:21:01 -0700 (Mon, 27 Aug 2007) Log Message: ----------- Simplified nick completion. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-26 23:06:21 UTC (rev 1147) +++ trunk/data/public/js/pfcclient.js 2007-08-27 14:21:01 UTC (rev 1148) @@ -660,7 +660,7 @@ } if (nick_match) { - w.value = non_nick_begin + nick_src.replace(nick_src, nick_replace) + non_nick_end; + w.value = non_nick_begin + nick_replace + non_nick_end; w.selStart = w.selEnd = non_nick_begin.length + nick_replace.length; // Move cursor to end of completed nick. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-30 16:40:38
|
Revision: 1168 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1168&view=rev Author: gpinzone Date: 2007-08-30 09:40:39 -0700 (Thu, 30 Aug 2007) Log Message: ----------- Added logic to only set class once. Class value would show up twice for browsers that supported both class and className. Also, all versions of IE need className. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-30 12:06:57 UTC (rev 1167) +++ trunk/data/public/js/pfcclient.js 2007-08-30 16:40:39 UTC (rev 1168) @@ -1197,14 +1197,18 @@ var nickidlst = this.getChanMeta(chanid,'users')['nickid']; var nickdiv = this.gui.getOnlineContentFromTabId(chanid); var ul = document.createElement('ul'); - ul.setAttribute('class', 'pfc_nicklist'); - ul.setAttribute('className', 'pfc_nicklist'); // IE6 + if (is_ie) + ul.setAttribute('className', 'pfc_nicklist'); // IE + else + ul.setAttribute('class', 'pfc_nicklist'); for (var i=0; i<nickidlst.length; i++) { var nickid = nickidlst[i]; var li = this.buildNickItem(nickid); - li.setAttribute('class', 'pfc_nickitem_'+nickid); - li.setAttribute('className', 'pfc_nickitem_'+nickid); // IE6 + if (is_ie) + li.setAttribute('className', 'pfc_nickitem_'+nickid); // IE + else + li.setAttribute('class', 'pfc_nickitem_'+nickid); ul.appendChild(li); } var fc = nickdiv.firstChild; @@ -1227,18 +1231,24 @@ var usermeta = this.getAllUserMeta(nickid); var div = document.createElement('div'); - div.setAttribute('class', 'pfc_nickwhois'); - div.setAttribute('className', 'pfc_nickwhois'); // for IE6 + if (is_ie) + div.setAttribute('className', 'pfc_nickwhois'); // for IE + else + div.setAttribute('class', 'pfc_nickwhois'); var p = document.createElement('p'); - p.setAttribute('class', 'pfc_nickwhois_header'); - p.setAttribute('className', 'pfc_nickwhois_header'); // for IE6 + if (is_ie) + p.setAttribute('className', 'pfc_nickwhois_header'); // for IE + else + p.setAttribute('class', 'pfc_nickwhois_header'); div.appendChild(p); // add the close button var img = document.createElement('img'); - img.setAttribute('class', 'pfc_nickwhois_close'); - img.setAttribute('className', 'pfc_nickwhois_close'); // for IE6 + if (is_ie) + img.setAttribute('className', 'pfc_nickwhois_close'); // for IE + else + img.setAttribute('class', 'pfc_nickwhois_close'); img.pfc_parent = div; img.onclick = function(evt){ this.pfc_parent.style.display = 'none'; @@ -1269,11 +1279,15 @@ { var tr = document.createElement('tr'); var td1 = document.createElement('td'); - td1.setAttribute('class', 'pfc_nickwhois_c1'); - td1.setAttribute('className', 'pfc_nickwhois_c1'); // for IE6 + if (is_ie) + td1.setAttribute('className', 'pfc_nickwhois_c1'); // for IE + else + td1.setAttribute('class', 'pfc_nickwhois_c1'); var td2 = document.createElement('td'); - td2.setAttribute('class', 'pfc_nickwhois_c2'); - td2.setAttribute('className', 'pfc_nickwhois_c2'); // for IE6 + if (is_ie) + td2.setAttribute('className', 'pfc_nickwhois_c2'); // for IE + else + td2.setAttribute('class', 'pfc_nickwhois_c2'); td1.appendChild(document.createTextNode(k)); td2.appendChild(document.createTextNode(v)); tr.appendChild(td1); @@ -1287,8 +1301,10 @@ if (pfc.getUserMeta(nickid,'nick') != this.nickname) { var p = document.createElement('p'); - p.setAttribute('class', 'pfc_nickwhois_pv'); - p.setAttribute('className', 'pfc_nickwhois_pv'); // for IE6 + if (is_ie) + p.setAttribute('className', 'pfc_nickwhois_pv'); // for IE + else + p.setAttribute('class', 'pfc_nickwhois_pv'); var a = document.createElement('a'); a.setAttribute('href', ''); a.pfc_nickid = nickid; @@ -1342,16 +1358,20 @@ else img.setAttribute('src', this.res.getFileUrl('images/user.gif')); img.style.marginRight = '5px'; - img.setAttribute('class', 'pfc_nickbutton'); - img.setAttribute('className', 'pfc_nickbutton'); // for IE6 + if (is_ie) + img.setAttribute('className', 'pfc_nickbutton'); // for IE + else + img.setAttribute('class', 'pfc_nickbutton'); a.appendChild(img); // nobr is not xhtml valid but it's a workeround // for IE which doesn't support 'white-space: pre' css rule var nobr = document.createElement('nobr'); var span = document.createElement('span'); - span.setAttribute('class', 'pfc_nickmarker pfc_nick_'+nickid); - span.setAttribute('className', 'pfc_nickmarker pfc_nick_'+nickid); // for IE6 + if (is_ie) + span.setAttribute('className', 'pfc_nickmarker pfc_nick_'+nickid); // for IE + else + span.setAttribute('class', 'pfc_nickmarker pfc_nick_'+nickid); span.appendChild(document.createTextNode(nick)); nobr.appendChild(span); a.appendChild(nobr); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-08 20:32:36
|
Revision: 1101 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1101&view=rev Author: gpinzone Date: 2007-08-08 13:32:35 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Command history fix for IE. Changed keys to Arrow Up/Down to emulate functionality in most IRC clients. Explorer doesn't fire the "keypress" event for Page Up/Down. Moved code to "keydown" area since "keypress" detection is too unreliable for some browsers. Tested on FF 2, IE 6, IE 7, and Opera. Ref: http://www.quirksmode.org/js/keys.html Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-08 07:17:57 UTC (rev 1100) +++ trunk/data/public/js/pfcclient.js 2007-08-08 20:32:35 UTC (rev 1101) @@ -25,9 +25,9 @@ this.chanmeta = $H(); this.nickwhoisbox = $H(); - // this array contains all the sent command - // used the up and down key to navigate in the history - // (doesn't work on IE6) + // this array contains all the sent commands + // use the up and down arrow key to navigate through the history + // may not work in Safari 1.3 this.cmdhistory = Array(); this.cmdhistoryid = -1; this.cmdhistoryissearching = false; @@ -627,8 +627,30 @@ { return this.doSendMessage(); } - else if (code == 33 && false) // page up key + else { + /* allow other keys */ + return true; + } + }, + /** + * Handle the pressed keys + * see also callbackWords_OnKeypress + */ + callbackWords_OnKeydown: function(evt) + { + if (!this.isconnected) return false; + this.clearError(Array(this.el_words)); + var code = (evt.which) ? evt.which : evt.keyCode + if (code == 9) /* tab key */ + { + /* IE workaround : ignore TAB key here */ + /* do the nickname completion work like on IRC */ + this.completeNick(); + return false; /* do not leave the tab key default behavior */ + } + else if (code == 38) // up arrow key + { // write the last command in the history if (this.cmdhistory.length>0) { @@ -641,7 +663,7 @@ w.value = this.cmdhistory[this.cmdhistoryid]; } } - else if (code == 34 && false) // page down key + else if (code == 40) // down arrow key { // write the next command in the history if (this.cmdhistory.length>0) @@ -657,31 +679,9 @@ } else { - /* allow other keys */ return true; } }, - /** - * Handle the pressed keys - * see also callbackWords_OnKeypress - */ - callbackWords_OnKeydown: function(evt) - { - if (!this.isconnected) return false; - this.clearError(Array(this.el_words)); - var code = (evt.which) ? evt.which : evt.keyCode - if (code == 9) /* tab key */ - { - /* IE workaround : ignore TAB key here */ - /* do the nickname completion work like on IRC */ - this.completeNick(); - return false; /* do not leave the tab key default behavior */ - } - else - { - return true; - } - }, callbackWords_OnFocus: function(evt) { // if (this.el_handle && this.el_handle.value == '' && !this.minmax_status) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gpi...@us...> - 2007-08-27 16:53:29
|
Revision: 1147 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1147&view=rev Author: gpinzone Date: 2007-08-26 16:06:21 -0700 (Sun, 26 Aug 2007) Log Message: ----------- Updated double-space search and replace to use positive and negative lookahead. Modified Paths: -------------- trunk/data/public/js/pfcclient.js Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-08-26 16:23:20 UTC (rev 1146) +++ trunk/data/public/js/pfcclient.js 2007-08-26 23:06:21 UTC (rev 1147) @@ -1435,9 +1435,9 @@ msg = msg.replace(rx, '$1'); } - // replace double spaces by entity - rx = new RegExp(' ','g'); - msg = msg.replace(rx, ' '); + // Replace double spaces outside of tags by " " entity. + rx = new RegExp(' (?= )(?![^<]*>)','g'); + msg = msg.replace(rx, ' '); // try to parse bbcode rx = new RegExp('\\[b\\](.+?)\\[\/b\\]','ig'); @@ -1471,7 +1471,7 @@ { // We don't want to replace smiley strings inside of tags. // Use negative lookahead to search for end of tag. - rx = new RegExp(RegExp.escape(sl[i]) + "(?![^<]*>)",'g'); + rx = new RegExp(RegExp.escape(sl[i]) + '(?![^<]*>)','g'); msg = msg.replace(rx, '<img src="'+ smileys[sl[i]] +'" alt="' + sl[i] + '" title="' + sl[i] + '" />'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |