some sanity

pull/2480/head
John McLear 2015-01-21 13:24:21 +00:00
parent eacf1118f8
commit 34d6b31c98
4 changed files with 47 additions and 63 deletions

View File

@ -19,8 +19,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
var _, $, jQuery, plugins, Ace2Common; var _, $, jQuery, plugins, Ace2Common, mybrowser;
mybrowser = require('./browser').browser;
Ace2Common = require('./ace2_common'); Ace2Common = require('./ace2_common');
plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins'); plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
@ -36,7 +36,6 @@ var isNodeText = Ace2Common.isNodeText,
noop = Ace2Common.noop; noop = Ace2Common.noop;
var hooks = require('./pluginfw/hooks'); var hooks = require('./pluginfw/hooks');
var browser = require('./browser').browser;
function Ace2Inner(){ function Ace2Inner(){
@ -599,7 +598,7 @@ function Ace2Inner(){
// Chrome can't handle the truth.. If CSS rule white-space:pre-wrap // Chrome can't handle the truth.. If CSS rule white-space:pre-wrap
// is true then any paste event will insert two lines.. // is true then any paste event will insert two lines..
if(browser.chrome){ if(mybrowser.chrome){
$("#innerdocbody").css({"white-space":"normal"}); $("#innerdocbody").css({"white-space":"normal"});
} }
@ -945,7 +944,7 @@ function Ace2Inner(){
showslinenumbers : function(value){ showslinenumbers : function(value){
hasLineNumbers = !! value; hasLineNumbers = !! value;
// disable line numbers on mobile devices // disable line numbers on mobile devices
// if (browser.mobile) hasLineNumbers = false; // if (mybrowser.mobile) hasLineNumbers = false;
setClassPresence(sideDiv, "sidedivhidden", !hasLineNumbers); setClassPresence(sideDiv, "sidedivhidden", !hasLineNumbers);
fixView(); fixView();
}, },
@ -1312,7 +1311,9 @@ function Ace2Inner(){
else else
{ {
var offsetIntoLine = 0; var offsetIntoLine = 0;
var filteredFunc = linestylefilter.getFilterStack(text, textAndClassFunc, browser); mybrowser.msie = false; // cake 1
var filteredFunc = linestylefilter.getFilterStack(text, textAndClassFunc, mybrowser);
mybrowser.msie = true;
var lineNum = rep.lines.indexOfEntry(lineEntry); var lineNum = rep.lines.indexOfEntry(lineEntry);
var aline = rep.alines[lineNum]; var aline = rep.alines[lineNum];
filteredFunc = linestylefilter.getLineStyleFilter( filteredFunc = linestylefilter.getLineStyleFilter(
@ -1560,13 +1561,16 @@ function Ace2Inner(){
lastDirtyNode = (lastDirtyNode && isNodeDirty(lastDirtyNode) && lastDirtyNode); lastDirtyNode = (lastDirtyNode && isNodeDirty(lastDirtyNode) && lastDirtyNode);
if (firstDirtyNode && lastDirtyNode) if (firstDirtyNode && lastDirtyNode)
{ {
var cc = makeContentCollector(isStyled, browser, rep.apool, null, className2Author); // cake 2
mybrowser.msie = false;
var cc = makeContentCollector(isStyled, mybrowser, rep.apool, null, className2Author);
mybrowser.msie = true;
cc.notifySelection(selection); cc.notifySelection(selection);
var dirtyNodes = []; var dirtyNodes = [];
for (var n = firstDirtyNode; n && !(n.previousSibling && n.previousSibling == lastDirtyNode); for (var n = firstDirtyNode; n && !(n.previousSibling && n.previousSibling == lastDirtyNode);
n = n.nextSibling) n = n.nextSibling)
{ {
if (browser.msie) if (mybrowser.msie)
{ {
// try to undo IE's pesky and overzealous linkification // try to undo IE's pesky and overzealous linkification
try try
@ -1606,7 +1610,7 @@ function Ace2Inner(){
if (linesWrapped > 0) if (linesWrapped > 0)
{ {
if(!browser.msie){ if(!mybrowser.msie){
// chrome decides in it's infinite wisdom that its okay to put the browsers visisble window in the middle of the span // chrome decides in it's infinite wisdom that its okay to put the browsers visisble window in the middle of the span
// an outcome of this is that the first chars of the string are no longer visible to the user.. Yay chrome.. // an outcome of this is that the first chars of the string are no longer visible to the user.. Yay chrome..
// Move the browsers visible area to the left hand side of the span // Move the browsers visible area to the left hand side of the span
@ -1911,7 +1915,7 @@ function Ace2Inner(){
if (charsLeft === 0) if (charsLeft === 0)
{ {
var index = 0; var index = 0;
if (browser.msie && line == (rep.lines.length() - 1) && lineNode.childNodes.length === 0) if (mybrowser.msie && line == (rep.lines.length() - 1) && lineNode.childNodes.length === 0)
{ {
// best to stay at end of last empty div in IE // best to stay at end of last empty div in IE
index = 1; index = 1;
@ -2904,7 +2908,7 @@ function Ace2Inner(){
function doCreateDomLine(nonEmpty) function doCreateDomLine(nonEmpty)
{ {
if (browser.msie && (!nonEmpty)) if (mybrowser.msie && (!nonEmpty))
{ {
var result = { var result = {
node: null, node: null,
@ -2965,8 +2969,10 @@ function Ace2Inner(){
} }
else else
{ {
// cake // cake 3
return domline.createDomLine(nonEmpty, doesWrap, browser, doc); mybrowser.msie = false;
return domline.createDomLine(nonEmpty, doesWrap, mybrowser, doc);
mybrowser.msie = true;
} }
} }
@ -3233,7 +3239,7 @@ function Ace2Inner(){
var dirtiness = {}; var dirtiness = {};
dirtiness.nodeId = uniqueId(n); dirtiness.nodeId = uniqueId(n);
dirtiness.knownHTML = n.innerHTML; dirtiness.knownHTML = n.innerHTML;
if (browser.msie) if (mybrowser.msie)
{ {
// adding a space to an "empty" div in IE designMode doesn't // adding a space to an "empty" div in IE designMode doesn't
// change the innerHTML of the div's parent; also, other // change the innerHTML of the div's parent; also, other
@ -3250,7 +3256,7 @@ function Ace2Inner(){
var data = getAssoc(n, "dirtiness"); var data = getAssoc(n, "dirtiness");
if (!data) return true; if (!data) return true;
if (n.id !== data.nodeId) return true; if (n.id !== data.nodeId) return true;
if (browser.msie) if (mybrowser.msie)
{ {
if (n.innerText !== data.knownText) return true; if (n.innerText !== data.knownText) return true;
} }
@ -3585,7 +3591,7 @@ function Ace2Inner(){
// On Mac and Linux, move right moves to end of word and move left moves to start; // On Mac and Linux, move right moves to end of word and move left moves to start;
// on Windows, always move to start of word. // on Windows, always move to start of word.
// On Windows, Firefox and IE disagree on whether to stop for punctuation (FF says no). // On Windows, Firefox and IE disagree on whether to stop for punctuation (FF says no).
if (browser.msie && forwardNotBack) if (mybrowser.msie && forwardNotBack)
{ {
while ((!isDone()) && isWordChar(nextChar())) while ((!isDone()) && isWordChar(nextChar()))
{ {
@ -3657,13 +3663,13 @@ function Ace2Inner(){
if (isModKey) return; if (isModKey) return;
// If the key is a keypress and the browser is opera and the key is enter, do nothign at all as this fires twice. // If the key is a keypress and the browser is opera and the key is enter, do nothign at all as this fires twice.
if (keyCode == 13 && browser.opera && (type == "keypress")){ if (keyCode == 13 && mybrowser.opera && (type == "keypress")){
return; // This stops double enters in Opera but double Tabs still show on single tab keypress, adding keyCode == 9 to this doesn't help as the event is fired twice return; // This stops double enters in Opera but double Tabs still show on single tab keypress, adding keyCode == 9 to this doesn't help as the event is fired twice
} }
var specialHandled = false; var specialHandled = false;
var isTypeForSpecialKey = ((browser.msie || browser.safari || browser.chrome) ? (type == "keydown") : (type == "keypress")); var isTypeForSpecialKey = ((mybrowser.msie || mybrowser.safari || mybrowser.chrome) ? (type == "keydown") : (type == "keypress"));
var isTypeForCmdKey = ((browser.msie || browser.safari || browser.chrome) ? (type == "keydown") : (type == "keypress")); var isTypeForCmdKey = ((mybrowser.msie || mybrowser.safari || mybrowser.chrome) ? (type == "keydown") : (type == "keypress"));
var stopped = false; var stopped = false;
@ -3880,7 +3886,7 @@ function Ace2Inner(){
/* Attempt to apply some sanity to cursor handling in Chrome after a copy / paste event /* Attempt to apply some sanity to cursor handling in Chrome after a copy / paste event
We have to do this the way we do because rep. doesn't hold the value for keyheld events IE if the user We have to do this the way we do because rep. doesn't hold the value for keyheld events IE if the user
presses and holds the arrow key .. Sorry if this is ugly, blame Chrome's weird handling of viewports after new content is added*/ presses and holds the arrow key .. Sorry if this is ugly, blame Chrome's weird handling of viewports after new content is added*/
if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && browser.chrome){ if((evt.which == 37 || evt.which == 38 || evt.which == 39 || evt.which == 40) && mybrowser.chrome){
var viewport = getViewPortTopBottom(); var viewport = getViewPortTopBottom();
var myselection = document.getSelection(); // get the current caret selection, can't use rep. here because that only gives us the start position not the current var myselection = document.getSelection(); // get the current caret selection, can't use rep. here because that only gives us the start position not the current
var caretOffsetTop = myselection.focusNode.parentNode.offsetTop || myselection.focusNode.offsetTop; // get the carets selection offset in px IE 214 var caretOffsetTop = myselection.focusNode.parentNode.offsetTop || myselection.focusNode.offsetTop; // get the carets selection offset in px IE 214
@ -3951,10 +3957,10 @@ function Ace2Inner(){
} }
// Is part of multi-keystroke international character on Firefox Mac // Is part of multi-keystroke international character on Firefox Mac
var isFirefoxHalfCharacter = (browser.mozilla && evt.altKey && charCode === 0 && keyCode === 0); var isFirefoxHalfCharacter = (mybrowser.firefox && evt.altKey && charCode === 0 && keyCode === 0);
// Is part of multi-keystroke international character on Safari Mac // Is part of multi-keystroke international character on Safari Mac
var isSafariHalfCharacter = (browser.safari && evt.altKey && keyCode == 229); var isSafariHalfCharacter = (mybrowser.safari && evt.altKey && keyCode == 229);
if (thisKeyDoesntTriggerNormalize || isFirefoxHalfCharacter || isSafariHalfCharacter) if (thisKeyDoesntTriggerNormalize || isFirefoxHalfCharacter || isSafariHalfCharacter)
{ {
@ -4068,7 +4074,7 @@ function Ace2Inner(){
// each of which has node (a magicdom node), index, and maxIndex. If the node // each of which has node (a magicdom node), index, and maxIndex. If the node
// is a text node, maxIndex is the length of the text; else maxIndex is 1. // is a text node, maxIndex is the length of the text; else maxIndex is 1.
// index is between 0 and maxIndex, inclusive. // index is between 0 and maxIndex, inclusive.
if (browser.msie) if (mybrowser.msie)
{ {
var browserSelection; var browserSelection;
try try
@ -4364,7 +4370,7 @@ function Ace2Inner(){
maxIndex: pt.maxIndex maxIndex: pt.maxIndex
}; };
} }
if (browser.msie) if (mybrowser.msie)
{ {
// Oddly enough, accessing scrollHeight fixes return key handling on IE 8, // Oddly enough, accessing scrollHeight fixes return key handling on IE 8,
// presumably by forcing some kind of internal DOM update. // presumably by forcing some kind of internal DOM update.
@ -4653,17 +4659,17 @@ function Ace2Inner(){
for (var i = 0; i < 2; i++) for (var i = 0; i < 2; i++)
{ {
var newHeight = root.clientHeight; var newHeight = root.clientHeight;
var newWidth = (browser.msie ? root.createTextRange().boundingWidth : root.clientWidth); var newWidth = root.clientWidth;
var viewHeight = getInnerHeight() - iframePadBottom - iframePadTop; var viewHeight = getInnerHeight() - iframePadBottom - iframePadTop;
var viewWidth = getInnerWidth() - iframePadLeft - iframePadRight; var viewWidth = getInnerWidth() - iframePadLeft - iframePadRight;
if (newHeight < viewHeight) if (newHeight < viewHeight)
{ {
newHeight = viewHeight; newHeight = viewHeight;
if (browser.msie) setIfNecessary(outerWin.document.documentElement.style, 'overflowY', 'auto'); // if (mybrowser.msie) setIfNecessary(outerWin.document.documentElement.style, 'overflowY', 'auto');
} }
else else
{ {
if (browser.msie) setIfNecessary(outerWin.document.documentElement.style, 'overflowY', 'scroll'); // if (mybrowser.msie) setIfNecessary(outerWin.document.documentElement.style, 'overflowY', 'scroll');
} }
if (doesWrap) if (doesWrap)
{ {
@ -4677,7 +4683,7 @@ function Ace2Inner(){
setIfNecessary(iframe.style, "width", newWidth + "px"); setIfNecessary(iframe.style, "width", newWidth + "px");
setIfNecessary(sideDiv.style, "height", newHeight + "px"); setIfNecessary(sideDiv.style, "height", newHeight + "px");
} }
if (browser.mozilla) if (mybrowser.firefox)
{ {
if (!doesWrap) if (!doesWrap)
{ {
@ -4776,14 +4782,14 @@ function Ace2Inner(){
} }
return false; return false;
} }
if (browser.msie || browser.safari) if (mybrowser.msie || mybrowser.safari)
{ {
setIfNecessary(root, 'contentEditable', (newVal ? 'true' : 'false')); setIfNecessary(root, 'contentEditable', (newVal ? 'true' : 'false'));
} }
else else
{ {
var wasSet = setIfNecessary(doc, 'designMode', (newVal ? 'on' : 'off')); var wasSet = setIfNecessary(doc, 'designMode', (newVal ? 'on' : 'off'));
if (wasSet && newVal && browser.opera) if (wasSet && newVal && mybrowser.opera)
{ {
// turning on designMode clears event handlers // turning on designMode clears event handlers
bindTheEventHandlers(); bindTheEventHandlers();
@ -4849,11 +4855,11 @@ function Ace2Inner(){
$(document).on("keyup", handleKeyEvent); $(document).on("keyup", handleKeyEvent);
$(document).on("click", handleClick); $(document).on("click", handleClick);
$(root).on("blur", handleBlur); $(root).on("blur", handleBlur);
if (browser.msie) if (mybrowser.msie)
{ {
$(document).on("click", handleIEOuterClick); $(document).on("click", handleIEOuterClick);
} }
if (browser.msie) $(root).on("paste", handleIEPaste); if (mybrowser.msie) $(root).on("paste", handleIEPaste);
// Don't paste on middle click of links // Don't paste on middle click of links
$(root).on("paste", function(e){ $(root).on("paste", function(e){
@ -4863,7 +4869,7 @@ function Ace2Inner(){
}) })
// CompositionEvent is not implemented below IE version 8 // CompositionEvent is not implemented below IE version 8
if ( !(browser.msie && browser.version <= 9) && document.documentElement) if ( !(mybrowser.msie && mybrowser.version <= 9) && document.documentElement)
{ {
$(document.documentElement).on("compositionstart", handleCompositionEvent); $(document.documentElement).on("compositionstart", handleCompositionEvent);
$(document.documentElement).on("compositionend", handleCompositionEvent); $(document.documentElement).on("compositionend", handleCompositionEvent);
@ -4926,7 +4932,7 @@ function Ace2Inner(){
function handleBlur(evt) function handleBlur(evt)
{ {
if (browser.msie) if (mybrowser.msie)
{ {
// a fix: in IE, clicking on a control like a button outside the // a fix: in IE, clicking on a control like a button outside the
// iframe can "blur" the editor, causing it to stop getting // iframe can "blur" the editor, causing it to stop getting
@ -4997,7 +5003,7 @@ function Ace2Inner(){
var win = outerWin; var win = outerWin;
var odoc = win.document; var odoc = win.document;
var h; var h;
if (browser.opera) h = win.innerHeight; if (mybrowser.opera) h = win.innerHeight;
else h = odoc.documentElement.clientHeight; else h = odoc.documentElement.clientHeight;
if (h) return h; if (h) return h;
@ -5326,20 +5332,9 @@ function Ace2Inner(){
{ {
var body = doc.getElementById("innerdocbody"); var body = doc.getElementById("innerdocbody");
root = body; // defined as a var in scope outside root = body; // defined as a var in scope outside
if (browser.mozilla) $(root).addClass("mozilla"); if (mybrowser.firefox) $(root).addClass("mozilla");
if (browser.safari) $(root).addClass("safari"); if (mybrowser.safari) $(root).addClass("safari");
if (browser.msie) $(root).addClass("msie"); if (mybrowser.msie) $(root).addClass("msie");
if (browser.msie)
{
// cache CSS background images
try
{
doc.execCommand("BackgroundImageCache", false, true);
}
catch (e)
{ /* throws an error in some IE 6 but not others! */
}
}
setClassPresence(root, "authorColors", true); setClassPresence(root, "authorColors", true);
setClassPresence(root, "doesWrap", doesWrap); setClassPresence(root, "doesWrap", doesWrap);

View File

@ -66,18 +66,6 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
} }
} }
// for IE
if (browser.msie)
{
try
{
document.execCommand("BackgroundImageCache", false, true);
}
catch (e)
{}
}
//var socket; //var socket;
var channelState = "DISCONNECTED"; var channelState = "DISCONNECTED";

View File

@ -82,7 +82,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
{} {}
}; };
if (browser.mozilla) if (browser.firefox)
{ {
// Prevent "escape" from taking effect and canceling a comet connection; // Prevent "escape" from taking effect and canceling a comet connection;
// doesn't work if focus is on an iframe. // doesn't work if focus is on an iframe.

View File

@ -494,7 +494,8 @@ var pad = {
pad.initTime = +(new Date()); pad.initTime = +(new Date());
pad.padOptions = clientVars.initialOptions; pad.padOptions = clientVars.initialOptions;
if ((!browser.msie) && (!(browser.mozilla && browser.version.indexOf("1.8.") == 0))) console.log("pad", browser);
if ((!browser.msie) && (!(browser.firefox && browser.version.indexOf("1.8.") == 0)))
{ {
document.domain = document.domain; // for comet document.domain = document.domain; // for comet
} }