summaryrefslogtreecommitdiff
path: root/src/static/js
diff options
context:
space:
mode:
authorPeter 'Pita' Martischka <petermartischka@googlemail.com>2013-02-03 14:03:10 +0000
committerPeter 'Pita' Martischka <petermartischka@googlemail.com>2013-02-03 14:03:10 +0000
commitcba001341f2b184684931591598838e1c750d86c (patch)
treeb35674f2bd2051f6f3efb6dff32441140e3743a3 /src/static/js
parentd30daccb10ac35690fc8bffa6723e41ae1274016 (diff)
downloadetherpad-lite-cba001341f2b184684931591598838e1c750d86c.zip
Remove legacy mozilla specific code from ace inner
Diffstat (limited to 'src/static/js')
-rw-r--r--src/static/js/ace2_common.js14
-rw-r--r--src/static/js/ace2_inner.js334
-rw-r--r--src/static/js/domline.js3
3 files changed, 2 insertions, 349 deletions
diff --git a/src/static/js/ace2_common.js b/src/static/js/ace2_common.js
index 8a7d16ee..fb7ce4fe 100644
--- a/src/static/js/ace2_common.js
+++ b/src/static/js/ace2_common.js
@@ -33,19 +33,6 @@ function object(o)
f.prototype = o;
return new f();
}
-var userAgent = (((function () {return this;})().navigator || {}).userAgent || 'node-js').toLowerCase();
-
-// Figure out what browser is being used (stolen from jquery 1.2.1)
-var browser = {
- version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
- safari: /webkit/.test(userAgent),
- opera: /opera/.test(userAgent),
- msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
- mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent),
- windows: /windows/.test(userAgent),
- mobile: /mobile/.test(userAgent) || /android/.test(userAgent)
-};
-
function getAssoc(obj, name)
{
@@ -97,7 +84,6 @@ var noop = function(){};
exports.isNodeText = isNodeText;
exports.object = object;
-exports.browser = browser;
exports.getAssoc = getAssoc;
exports.setAssoc = setAssoc;
exports.binarySearch = binarySearch;
diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js
index 848fc20b..95ffb038 100644
--- a/src/static/js/ace2_inner.js
+++ b/src/static/js/ace2_inner.js
@@ -28,7 +28,7 @@ $ = jQuery = require('./rjquery').$;
_ = require("./underscore");
var isNodeText = Ace2Common.isNodeText,
- browser = Ace2Common.browser,
+ browser = $.browser,
getAssoc = Ace2Common.getAssoc,
setAssoc = Ace2Common.setAssoc,
isTextNode = Ace2Common.isTextNode,
@@ -2817,7 +2817,6 @@ function Ace2Inner(){
rep.selStart = selectStart;
rep.selEnd = selectEnd;
rep.selFocusAtStart = newSelFocusAtStart;
- if (mozillaFakeArrows) mozillaFakeArrows.notifySelectionChanged();
currentCallStack.repChanged = true;
return true;
@@ -3690,12 +3689,6 @@ function Ace2Inner(){
doDeleteKey();
specialHandled = true;
}
-
- if (mozillaFakeArrows && mozillaFakeArrows.handleKeyEvent(evt))
- {
- evt.preventDefault();
- specialHandled = true;
- }
}
if (type == "keydown")
@@ -5037,331 +5030,6 @@ function Ace2Inner(){
}
editorInfo.ace_doInsertUnorderedList = doInsertUnorderedList;
editorInfo.ace_doInsertOrderedList = doInsertOrderedList;
-
- var mozillaFakeArrows = (browser.mozilla && (function()
- {
- // In Firefox 2, arrow keys are unstable while DOM-manipulating
- // operations are going on. Specifically, if an operation
- // (computation that ties up the event queue) is going on (in the
- // call-stack of some event, like a timeout) that at some point
- // mutates nodes involved in the selection, then the arrow
- // keypress may (randomly) move the caret to the beginning or end
- // of the document. If the operation also mutates the selection
- // range, the old selection or the new selection may be used, or
- // neither.
- // As long as the arrow is pressed during the busy operation, it
- // doesn't seem to matter that the keydown and keypress events
- // aren't generated until afterwards, or that the arrow movement
- // can still be stopped (meaning it hasn't been performed yet);
- // Firefox must be preserving some old information about the
- // selection or the DOM from when the key was initially pressed.
- // However, it also doesn't seem to matter when the key was
- // actually pressed relative to the time of the mutation within
- // the prolonged operation. Also, even in very controlled tests
- // (like a mutation followed by a long period of busyWaiting), the
- // problem shows up often but not every time, with no discernable
- // pattern. Who knows, it could have something to do with the
- // caret-blinking timer, or DOM changes not being applied
- // immediately.
- // This problem, mercifully, does not show up at all in IE or
- // Safari. My solution is to have my own, full-featured arrow-key
- // implementation for Firefox.
- // Note that the problem addressed here is potentially very subtle,
- // especially if the operation is quick and is timed to usually happen
- // when the user is idle.
- // features:
- // - 'up' and 'down' arrows preserve column when passing through shorter lines
- // - shift-arrows extend the "focus" point, which may be start or end of range
- // - the focus point is kept horizontally and vertically scrolled into view
- // - arrows without shift cause caret to move to beginning or end of selection (left,right)
- // or move focus point up or down a line (up,down)
- // - command-(left,right,up,down) on Mac acts like (line-start, line-end, doc-start, doc-end)
- // - takes wrapping into account when doesWrap is true, i.e. up-arrow and down-arrow move
- // between the virtual lines within a wrapped line; this was difficult, and unfortunately
- // requires mutating the DOM to get the necessary information
- var savedFocusColumn = 0; // a value of 0 has no effect
- var updatingSelectionNow = false;
-
- function getVirtualLineView(lineNum)
- {
- var lineNode = rep.lines.atIndex(lineNum).lineNode;
- while (lineNode.firstChild && isBlockElement(lineNode.firstChild))
- {
- lineNode = lineNode.firstChild;
- }
- return makeVirtualLineView(lineNode);
- }
-
- function markerlessLineAndChar(line, chr)
- {
- return [line, chr - rep.lines.atIndex(line).lineMarker];
- }
-
- function markerfulLineAndChar(line, chr)
- {
- return [line, chr + rep.lines.atIndex(line).lineMarker];
- }
-
- return {
- notifySelectionChanged: function()
- {
- if (!updatingSelectionNow)
- {
- savedFocusColumn = 0;
- }
- },
- handleKeyEvent: function(evt)
- {
- // returns "true" if handled
- if (evt.type != "keypress") return false;
- var keyCode = evt.keyCode;
- if (keyCode < 37 || keyCode > 40) return false;
- incorporateUserChanges();
-
- if (!(rep.selStart && rep.selEnd)) return true;
-
- // {byWord,toEnd,normal}
- var moveMode = (evt.altKey ? "byWord" : (evt.ctrlKey ? "byWord" : (evt.metaKey ? "toEnd" : "normal")));
-
- var anchorCaret = markerlessLineAndChar(rep.selStart[0], rep.selStart[1]);
- var focusCaret = markerlessLineAndChar(rep.selEnd[0], rep.selEnd[1]);
- var wasCaret = isCaret();
- if (rep.selFocusAtStart)
- {
- var tmp = anchorCaret;
- anchorCaret = focusCaret;
- focusCaret = tmp;
- }
- var K_UP = 38,
- K_DOWN = 40,
- K_LEFT = 37,
- K_RIGHT = 39;
- var dontMove = false;
- if (wasCaret && !evt.shiftKey)
- {
- // collapse, will mutate both together
- anchorCaret = focusCaret;
- }
- else if ((!wasCaret) && (!evt.shiftKey))
- {
- if (keyCode == K_LEFT)
- {
- // place caret at beginning
- if (rep.selFocusAtStart) anchorCaret = focusCaret;
- else focusCaret = anchorCaret;
- if (moveMode == "normal") dontMove = true;
- }
- else if (keyCode == K_RIGHT)
- {
- // place caret at end
- if (rep.selFocusAtStart) focusCaret = anchorCaret;
- else anchorCaret = focusCaret;
- if (moveMode == "normal") dontMove = true;
- }
- else
- {
- // collapse, will mutate both together
- anchorCaret = focusCaret;
- }
- }
- if (!dontMove)
- {
- function lineLength(i)
- {
- var entry = rep.lines.atIndex(i);
- return entry.text.length - entry.lineMarker;
- }
-
- function lineText(i)
- {
- var entry = rep.lines.atIndex(i);
- return entry.text.substring(entry.lineMarker);
- }
-
- if (keyCode == K_UP || keyCode == K_DOWN)
- {
- var up = (keyCode == K_UP);
- var canChangeLines = ((up && focusCaret[0]) || ((!up) && focusCaret[0] < rep.lines.length() - 1));
- var virtualLineView, virtualLineSpot, canChangeVirtualLines = false;
- if (doesWrap)
- {
- virtualLineView = getVirtualLineView(focusCaret[0]);
- virtualLineSpot = virtualLineView.getVLineAndOffsetForChar(focusCaret[1]);
- canChangeVirtualLines = ((up && virtualLineSpot.vline > 0) || ((!up) && virtualLineSpot.vline < (
- virtualLineView.getNumVirtualLines() - 1)));
- }
- var newColByVirtualLineChange;
- if (moveMode == "toEnd")
- {
- if (up)
- {
- focusCaret[0] = 0;
- focusCaret[1] = 0;
- }
- else
- {
- focusCaret[0] = rep.lines.length() - 1;
- focusCaret[1] = lineLength(focusCaret[0]);
- }
- }
- else if (moveMode == "byWord")
- {
- // move by "paragraph", a feature that Firefox lacks but IE and Safari both have
- if (up)
- {
- if (focusCaret[1] === 0 && canChangeLines)
- {
- focusCaret[0]--;
- focusCaret[1] = 0;
- }
- else focusCaret[1] = 0;
- }
- else
- {
- var lineLen = lineLength(focusCaret[0]);
- if (browser.windows)
- {
- if (canChangeLines)
- {
- focusCaret[0]++;
- focusCaret[1] = 0;
- }
- else
- {
- focusCaret[1] = lineLen;
- }
- }
- else
- {
- if (focusCaret[1] == lineLen && canChangeLines)
- {
- focusCaret[0]++;
- focusCaret[1] = lineLength(focusCaret[0]);
- }
- else
- {
- focusCaret[1] = lineLen;
- }
- }
- }
- savedFocusColumn = 0;
- }
- else if (canChangeVirtualLines)
- {
- var vline = virtualLineSpot.vline;
- var offset = virtualLineSpot.offset;
- if (up) vline--;
- else vline++;
- if (savedFocusColumn > offset) offset = savedFocusColumn;
- else
- {
- savedFocusColumn = offset;
- }
- var newSpot = virtualLineView.getCharForVLineAndOffset(vline, offset);
- focusCaret[1] = newSpot.lineChar;
- }
- else if (canChangeLines)
- {
- if (up) focusCaret[0]--;
- else focusCaret[0]++;
- var offset = focusCaret[1];
- if (doesWrap)
- {
- offset = virtualLineSpot.offset;
- }
- if (savedFocusColumn > offset) offset = savedFocusColumn;
- else
- {
- savedFocusColumn = offset;
- }
- if (doesWrap)
- {
- var newLineView = getVirtualLineView(focusCaret[0]);
- var vline = (up ? newLineView.getNumVirtualLines() - 1 : 0);
- var newSpot = newLineView.getCharForVLineAndOffset(vline, offset);
- focusCaret[1] = newSpot.lineChar;
- }
- else
- {
- var lineLen = lineLength(focusCaret[0]);
- if (offset > lineLen) offset = lineLen;
- focusCaret[1] = offset;
- }
- }
- else
- {
- if (up) focusCaret[1] = 0;
- else focusCaret[1] = lineLength(focusCaret[0]);
- savedFocusColumn = 0;
- }
- }
- else if (keyCode == K_LEFT || keyCode == K_RIGHT)
- {
- var left = (keyCode == K_LEFT);
- if (left)
- {
- if (moveMode == "toEnd") focusCaret[1] = 0;
- else if (focusCaret[1] > 0)
- {
- if (moveMode == "byWord")
- {
- focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], false);
- }
- else
- {
- focusCaret[1]--;
- }
- }
- else if (focusCaret[0] > 0)
- {
- focusCaret[0]--;
- focusCaret[1] = lineLength(focusCaret[0]);
- if (moveMode == "byWord")
- {
- focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], false);
- }
- }
- }
- else
- {
- var lineLen = lineLength(focusCaret[0]);
- if (moveMode == "toEnd") focusCaret[1] = lineLen;
- else if (focusCaret[1] < lineLen)
- {
- if (moveMode == "byWord")
- {
- focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], true);
- }
- else
- {
- focusCaret[1]++;
- }
- }
- else if (focusCaret[0] < rep.lines.length() - 1)
- {
- focusCaret[0]++;
- focusCaret[1] = 0;
- if (moveMode == "byWord")
- {
- focusCaret[1] = moveByWordInLine(lineText(focusCaret[0]), focusCaret[1], true);
- }
- }
- }
- savedFocusColumn = 0;
- }
- }
-
- var newSelFocusAtStart = ((focusCaret[0] < anchorCaret[0]) || (focusCaret[0] == anchorCaret[0] && focusCaret[1] < anchorCaret[1]));
- var newSelStart = (newSelFocusAtStart ? focusCaret : anchorCaret);
- var newSelEnd = (newSelFocusAtStart ? anchorCaret : focusCaret);
- updatingSelectionNow = true;
- performSelectionChange(markerfulLineAndChar(newSelStart[0], newSelStart[1]), markerfulLineAndChar(newSelEnd[0], newSelEnd[1]), newSelFocusAtStart);
- updatingSelectionNow = false;
- currentCallStack.userChangedSelection = true;
- return true;
- }
- };
- })());
var lineNumbersShown;
var sideDivInner;
diff --git a/src/static/js/domline.js b/src/static/js/domline.js
index 1be0f4ee..43b5f21a 100644
--- a/src/static/js/domline.js
+++ b/src/static/js/domline.js
@@ -30,8 +30,7 @@ var Security = require('./security');
var hooks = require('./pluginfw/hooks');
var _ = require('./underscore');
var lineAttributeMarker = require('./linestylefilter').lineAttributeMarker;
-var Ace2Common = require('./ace2_common');
-var noop = Ace2Common.noop;
+var noop = function(){};
var domline = {};