From 4044d5ae476725ef44442c4d507685205642cadb Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:14:01 +0100 Subject: [PATCH 01/18] remove hidden input field padId which is send on every import but not used --- src/templates/pad.html | 1 - 1 file changed, 1 deletion(-) diff --git a/src/templates/pad.html b/src/templates/pad.html index bea0f03c..dd989e7f 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -273,7 +273,6 @@
- From f25fed1c252c781bd64b9ff4b3bfc70cdc863908 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:15:38 +0100 Subject: [PATCH 02/18] [ace2_inner] remove incorpIfQuick because its unused since July --- src/static/js/ace2_inner.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 63e6e1f4..6c27a819 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1173,34 +1173,6 @@ function Ace2Inner(){ } editorInfo.ace_fastIncorp = fastIncorp; - function incorpIfQuick() - { - var me = incorpIfQuick; - var failures = (me.failures || 0); - if (failures < 5) - { - var isTimeUp = newTimeLimit(40); - var madeChanges = incorporateUserChanges(isTimeUp); - if (isTimeUp()) - { - me.failures = failures + 1; - } - return true; - } - else - { - var skipCount = (me.skipCount || 0); - skipCount++; - if (skipCount == 20) - { - skipCount = 0; - me.failures = 0; - } - me.skipCount = skipCount; - } - return false; - } - var idleWorkTimer = makeIdleAction(function() { From 8175af30172b05375effcde679b4cea70ce67839 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:20:53 +0100 Subject: [PATCH 03/18] [collab_client] remove socketid because its not used --- src/static/js/broadcast.js | 1 - src/static/js/collab_client.js | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js index 6bd135bd..d4bda111 100644 --- a/src/static/js/broadcast.js +++ b/src/static/js/broadcast.js @@ -77,7 +77,6 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro } - var socketId; //var socket; var channelState = "DISCONNECTED"; diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index ec56264f..8dfcfc64 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -44,7 +44,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) var state = "IDLE"; var stateMessage; - var stateMessageSocketId; var channelState = "CONNECTING"; var appLevelDisconnectReason = null; @@ -52,7 +51,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) var initialStartConnectTime = 0; var userId = initialUserInfo.userId; - var socketId; //var socket; var userSet = {}; // userId -> userInfo userSet[userId] = initialUserInfo; @@ -196,7 +194,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) changeset: userChangesData.changeset, apool: userChangesData.apool }; - stateMessageSocketId = socketId; sendMessage(stateMessage); sentMessage = true; callbacks.onInternalAction("commitPerformed"); @@ -593,7 +590,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) { obj.committedChangeset = stateMessage.changeset; obj.committedChangesetAPool = stateMessage.apool; - obj.committedChangesetSocketId = stateMessageSocketId; editor.applyPreparedChangesetToBase(); } var userChangesData = editor.prepareUserChangeset(); From eee355979d8c3a13a8c6b8c5f906c1a124e1e1aa Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:21:27 +0100 Subject: [PATCH 04/18] [ace2_inner] remove unused function htmlForRemovedChild --- src/static/js/ace2_inner.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 6c27a819..6793127a 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1779,13 +1779,6 @@ function Ace2Inner(){ return domChanges; } - function htmlForRemovedChild(n) - { - var div = doc.createElement("DIV"); - div.appendChild(n); - return div.innerHTML; - } - var STYLE_ATTRIBS = { bold: true, italic: true, From 3dc844eb084bfbd9008e72a02edbe51e490d18c6 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:21:53 +0100 Subject: [PATCH 05/18] [ace2_inner] remove unused getLineKeyForOffset that was part of old recolor module --- src/static/js/ace2_inner.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 6793127a..9d0689a6 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -561,12 +561,6 @@ function Ace2Inner(){ } } - function getLineKeyForOffset(charOffset) - { - return rep.lines.atOffset(charOffset).key; - } - - function dispose() { disposed = true; From a714f63597fe433319e36eed3c9cc8b5012584fb Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:22:20 +0100 Subject: [PATCH 06/18] [ace2inner] remove unused recolorLineByKey that was part of old recolor module --- src/static/js/ace2_inner.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 9d0689a6..3f9a9e2e 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -551,16 +551,6 @@ function Ace2Inner(){ } editorInfo.ace_inCallStackIfNecessary = inCallStackIfNecessary; - function recolorLineByKey(key) - { - if (rep.lines.containsKey(key)) - { - var offset = rep.lines.offsetOfKey(key); - var width = rep.lines.atKey(key).width; - recolorLinesInRange(offset, offset + width); - } - } - function dispose() { disposed = true; From 4dd3584532a862caa7ce058325fde4f793fe5b32 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:22:55 +0100 Subject: [PATCH 07/18] [ace2inner] remove unused function boldColorFromColor --- src/static/js/ace2_inner.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 3f9a9e2e..2798de44 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -346,19 +346,6 @@ function Ace2Inner(){ } } - function boldColorFromColor(lightColorCSS) - { - var color = colorutils.css2triple(lightColorCSS); - - // amp up the saturation to full - color = colorutils.saturate(color); - - // normalize brightness based on luminosity - color = colorutils.scaleColor(color, 0, 0.5 / colorutils.luminosity(color)); - - return colorutils.triple2css(color); - } - function fadeColor(colorCSS, fadeFrac) { var color = colorutils.css2triple(colorCSS); From 020bd3915c8cfaccfffbe12c563912f6dc7eaede Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:24:12 +0100 Subject: [PATCH 08/18] remove empty&unused overlaysdiv --- src/static/css/iframe_editor.css | 2 -- src/static/js/ace.js | 2 +- src/static/js/ace2_inner.js | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/static/css/iframe_editor.css b/src/static/css/iframe_editor.css index ddb509f4..beec4971 100644 --- a/src/static/css/iframe_editor.css +++ b/src/static/css/iframe_editor.css @@ -159,8 +159,6 @@ p { font-family: monospace; /* overridden by lineMetricsDiv.style */ } -#overlaysdiv { position: absolute; left: -1000px; top: -1000px; } - /* Stops super long lines without being spaces such as aaaaaaaaaaaaaa*100 breaking the editor Commented out because it stops IE from being able to render the document, crazy IE bug is crazy. */ /* diff --git a/src/static/js/ace.js b/src/static/js/ace.js index db0d596b..d2bbb484 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -313,7 +313,7 @@ window.onload = function () {\n\ // bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly // (throbs busy while typing) - outerHTML.push('', '', scriptTag(outerScript), '
x
'); + outerHTML.push('', '', scriptTag(outerScript), '
x
'); var outerFrame = document.createElement("IFRAME"); outerFrame.name = "ace_outer"; diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 2798de44..ec842285 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -79,7 +79,6 @@ function Ace2Inner(){ iframe.ace_outerWin = null; // prevent IE 6 memory leak var sideDiv = iframe.nextSibling; var lineMetricsDiv = sideDiv.nextSibling; - var overlaysdiv = lineMetricsDiv.nextSibling; initLineNumbers(); var outsideKeyDown = noop; From e04f46d4775037d712c5fa07dedda58e443b43d2 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:25:12 +0100 Subject: [PATCH 09/18] [ace2_inner] init() has replaced setup(), reflect this change in the comments and remove the unused setup() --- src/static/js/ace2_inner.js | 52 ++----------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index ec842285..9391e4ed 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -101,13 +101,13 @@ function Ace2Inner(){ apool: new AttribPool() }; - // lines, alltext, alines, and DOM are set up in setup() + // lines, alltext, alines, and DOM are set up in init() if (undoModule.enabled) { undoModule.apool = rep.apool; } - var root, doc; // set in setup() + var root, doc; // set in init() var isEditable = true; var doesWrap = true; var hasLineNumbers = true; @@ -4768,54 +4768,6 @@ function Ace2Inner(){ else $(elem).removeClass(className); } - function setup() - { - doc = document; // defined as a var in scope outside - inCallStackIfNecessary("setup", function() - { - var body = doc.getElementById("innerdocbody"); - root = body; // defined as a var in scope outside - if (browser.mozilla) addClass(root, "mozilla"); - if (browser.safari) addClass(root, "safari"); - if (browser.msie) addClass(root, "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, "doesWrap", doesWrap); - - initDynamicCSS(); - - enforceEditability(); - - // set up dom and rep - while (root.firstChild) root.removeChild(root.firstChild); - var oneEntry = createDomLineEntry(""); - doRepLineSplice(0, rep.lines.length(), [oneEntry]); - insertDomLines(null, [oneEntry.domInfo], null); - rep.alines = Changeset.splitAttributionLines( - Changeset.makeAttribution("\n"), "\n"); - - bindTheEventHandlers(); - - }); - - scheduler.setTimeout(function() - { - parent.readyFunc(); // defined in code that sets up the inner iframe - }, 0); - - isSetUp = true; - } - function focus() { window.focus(); From 021db28a0234fe524717642463490c1b3e37e711 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:27:48 +0100 Subject: [PATCH 10/18] [Changeset] a?lines_length was not used within inverse function --- src/static/js/Changeset.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index 77bd3a4c..e47b3052 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -1841,14 +1841,6 @@ exports.inverse = function (cs, lines, alines, pool) { } } - function lines_length() { - if ((typeof lines.length) == "number") { - return lines.length; - } else { - return lines.length(); - } - } - function alines_get(idx) { if (alines.get) { return alines.get(idx); @@ -1857,14 +1849,6 @@ exports.inverse = function (cs, lines, alines, pool) { } } - function alines_length() { - if ((typeof alines.length) == "number") { - return alines.length; - } else { - return alines.length(); - } - } - var curLine = 0; var curChar = 0; var curLineOpIter = null; From ca6f877db20a7f12d3bbed0409cdb2b32dae7569 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:28:43 +0100 Subject: [PATCH 11/18] [padDiff] remove unused functions a?lines_length --- src/node/utils/padDiff.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/node/utils/padDiff.js b/src/node/utils/padDiff.js index c5354041..88fa5cba 100644 --- a/src/node/utils/padDiff.js +++ b/src/node/utils/padDiff.js @@ -331,14 +331,6 @@ PadDiff.prototype._createDeletionChangeset = function(cs, startAText, apool) { } } - function lines_length() { - if ((typeof lines.length) == "number") { - return lines.length; - } else { - return lines.length(); - } - } - function alines_get(idx) { if (alines.get) { return alines.get(idx); @@ -347,14 +339,6 @@ PadDiff.prototype._createDeletionChangeset = function(cs, startAText, apool) { } } - function alines_length() { - if ((typeof alines.length) == "number") { - return alines.length; - } else { - return alines.length(); - } - } - var curLine = 0; var curChar = 0; var curLineOpIter = null; From aadcfbb3d153c191109a7fce1ac2795c220611cc Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:29:41 +0100 Subject: [PATCH 12/18] do not send globalPadId in clientvars - its not used anywhere --- src/node/handler/PadMessageHandler.js | 2 -- src/static/js/collab_client.js | 1 - 2 files changed, 3 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 75ec6bd7..748b8382 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1076,7 +1076,6 @@ function handleClientReady(client, message) "historicalAuthorData": historicalAuthorData, "apool": apool, "rev": pad.getHeadRevisionNumber(), - "globalPadId": message.padId, "time": currentTime, }, "colorPalette": authorManager.getColorPalette(), @@ -1093,7 +1092,6 @@ function handleClientReady(client, message) "readOnlyId": padIds.readOnlyPadId, "readonly": padIds.readonly, "serverTimestamp": new Date().getTime(), - "globalPadId": message.padId, "userId": author, "abiwordAvailable": settings.abiwordAvailable(), "plugins": { diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index 8dfcfc64..b51b0809 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -40,7 +40,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) var rev = serverVars.rev; var padId = serverVars.padId; - var globalPadId = serverVars.globalPadId; var state = "IDLE"; var stateMessage; From 6aaf4c40655d04c14a2d1dc98ceca4dde4fb3e70 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:30:25 +0100 Subject: [PATCH 13/18] [collab_client] remove keys function, which was not used and variable reconnectTimes which was used for some long gone disconnect tracking code --- src/static/js/collab_client.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index b51b0809..ce732b58 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -54,7 +54,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) var userSet = {}; // userId -> userInfo userSet[userId] = initialUserInfo; - var reconnectTimes = []; var caughtErrors = []; var caughtErrorCatchers = []; var caughtErrorTimes = []; @@ -501,16 +500,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) } } - function keys(obj) - { - var array = []; - $.each(obj, function(k, v) - { - array.push(k); - }); - return array; - } - function valuesArray(obj) { var array = []; From 1fa8c2a7e61b75c8976fb5bcb3b7ae6dde6493e8 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:30:48 +0100 Subject: [PATCH 14/18] [collab_client] remove unused function getStats --- src/static/js/collab_client.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index ce732b58..146ec51b 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -204,17 +204,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) } } - function getStats() - { - var stats = {}; - - stats.screen = [$(window).width(), $(window).height(), window.screen.availWidth, window.screen.availHeight, window.screen.width, window.screen.height].join(','); - stats.ip = serverVars.clientIp; - stats.useragent = serverVars.clientAgent; - - return stats; - } - function setUpSocket() { hiccupCount = 0; From 906ab1820b8555d018cb783840e7b368edfdfbe8 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:31:18 +0100 Subject: [PATCH 15/18] [timeslider] do not include underscore, as its not (longer) used --- src/static/js/timeslider.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/static/js/timeslider.js b/src/static/js/timeslider.js index 19489961..fd22c69a 100644 --- a/src/static/js/timeslider.js +++ b/src/static/js/timeslider.js @@ -28,7 +28,6 @@ JSON = require('./json2'); var createCookie = require('./pad_utils').createCookie; var readCookie = require('./pad_utils').readCookie; var randomString = require('./pad_utils').randomString; -var _ = require('./underscore'); var hooks = require('./pluginfw/hooks'); var token, padId, export_links; From ab797c9831d08f521fb0dfdd1e776d36b0945e91 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:31:46 +0100 Subject: [PATCH 16/18] [pad_connectionstatus] padeditbar is not used anywhere in pad_connectionstatus --- src/static/js/pad_connectionstatus.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/static/js/pad_connectionstatus.js b/src/static/js/pad_connectionstatus.js index 4cbf1642..76eedbc4 100644 --- a/src/static/js/pad_connectionstatus.js +++ b/src/static/js/pad_connectionstatus.js @@ -21,7 +21,6 @@ */ var padmodals = require('./pad_modals').padmodals; -var padeditbar = require('./pad_editbar').padeditbar; var padconnectionstatus = (function() { From 9400425b1eef135cc671c866da39c116d7e82b17 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:33:58 +0100 Subject: [PATCH 17/18] [virtual_lines] remove traces of virtual_lines/makeVirtualLineView. this code was used for FF2 key handling code and is long unused --- src/node/utils/tar.json | 1 - src/static/js/ace2_inner.js | 1 - src/static/js/virtual_lines.js | 388 --------------------------------- 3 files changed, 390 deletions(-) delete mode 100644 src/static/js/virtual_lines.js diff --git a/src/node/utils/tar.json b/src/node/utils/tar.json index b010f851..70001f8f 100644 --- a/src/node/utils/tar.json +++ b/src/node/utils/tar.json @@ -46,7 +46,6 @@ , "Changeset.js" , "ChangesetUtils.js" , "skiplist.js" - , "virtual_lines.js" , "cssmanager.js" , "colorutils.js" , "undomodule.js" diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 9391e4ed..1c5fcad5 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -51,7 +51,6 @@ function Ace2Inner(){ var linestylefilter = require('./linestylefilter').linestylefilter; var SkipList = require('./skiplist'); var undoModule = require('./undomodule').undoModule; - var makeVirtualLineView = require('./virtual_lines').makeVirtualLineView; var AttributeManager = require('./AttributeManager'); var DEBUG = false; //$$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;" diff --git a/src/static/js/virtual_lines.js b/src/static/js/virtual_lines.js deleted file mode 100644 index 2bcf5ed6..00000000 --- a/src/static/js/virtual_lines.js +++ /dev/null @@ -1,388 +0,0 @@ -/** - * This code is mostly from the old Etherpad. Please help us to comment this code. - * This helps other people to understand this code better and helps them to improve it. - * TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED - */ - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function makeVirtualLineView(lineNode) -{ - - // how much to jump forward or backward at once in a charSeeker before - // constructing a DOM node and checking the coordinates (which takes a - // significant fraction of a millisecond). From the - // coordinates and the approximate line height we can estimate how - // many lines we have moved. We risk being off if the number of lines - // we move is on the order of the line height in pixels. Fortunately, - // when the user boosts the font-size they increase both. - var maxCharIncrement = 20; - var seekerAtEnd = null; - - function getNumChars() - { - return lineNode.textContent.length; - } - - function getNumVirtualLines() - { - if (!seekerAtEnd) - { - var seeker = makeCharSeeker(); - seeker.forwardByWhile(maxCharIncrement); - seekerAtEnd = seeker; - } - return seekerAtEnd.getVirtualLine() + 1; - } - - function getVLineAndOffsetForChar(lineChar) - { - var seeker = makeCharSeeker(); - seeker.forwardByWhile(maxCharIncrement, null, lineChar); - var theLine = seeker.getVirtualLine(); - seeker.backwardByWhile(8, function() - { - return seeker.getVirtualLine() == theLine; - }); - seeker.forwardByWhile(1, function() - { - return seeker.getVirtualLine() != theLine; - }); - var lineStartChar = seeker.getOffset(); - return { - vline: theLine, - offset: (lineChar - lineStartChar) - }; - } - - function getCharForVLineAndOffset(vline, offset) - { - // returns revised vline and offset as well as absolute char index within line. - // if offset is beyond end of line, for example, will give new offset at end of line. - var seeker = makeCharSeeker(); - // go to start of line - seeker.binarySearch(function() - { - return seeker.getVirtualLine() >= vline; - }); - var lineStart = seeker.getOffset(); - var theLine = seeker.getVirtualLine(); - // go to offset, overshooting the virtual line only if offset is too large for it - seeker.forwardByWhile(maxCharIncrement, null, lineStart + offset); - // get back into line - seeker.backwardByWhile(1, function() - { - return seeker.getVirtualLine() != theLine; - }, lineStart); - var lineChar = seeker.getOffset(); - var theOffset = lineChar - lineStart; - // handle case of last virtual line; should be able to be at end of it - if (theOffset < offset && theLine == (getNumVirtualLines() - 1)) - { - var lineLen = getNumChars(); - theOffset += lineLen - lineChar; - lineChar = lineLen; - } - - return { - vline: theLine, - offset: theOffset, - lineChar: lineChar - }; - } - - return { - getNumVirtualLines: getNumVirtualLines, - getVLineAndOffsetForChar: getVLineAndOffsetForChar, - getCharForVLineAndOffset: getCharForVLineAndOffset, - makeCharSeeker: function() - { - return makeCharSeeker(); - } - }; - - function deepFirstChildTextNode(nd) - { - nd = nd.firstChild; - while (nd && nd.firstChild) nd = nd.firstChild; - if (nd.data) return nd; - return null; - } - - function makeCharSeeker( /*lineNode*/ ) - { - - function charCoords(tnode, i) - { - var container = tnode.parentNode; - - // treat space specially; a space at the end of a virtual line - // will have weird coordinates - var isSpace = (tnode.nodeValue.charAt(i) === " "); - if (isSpace) - { - if (i == 0) - { - if (container.previousSibling && deepFirstChildTextNode(container.previousSibling)) - { - tnode = deepFirstChildTextNode(container.previousSibling); - i = tnode.length - 1; - container = tnode.parentNode; - } - else - { - return { - top: container.offsetTop, - left: container.offsetLeft - }; - } - } - else - { - i--; // use previous char - } - } - - - var charWrapper = document.createElement("SPAN"); - - // wrap the character - var tnodeText = tnode.nodeValue; - var frag = document.createDocumentFragment(); - frag.appendChild(document.createTextNode(tnodeText.substring(0, i))); - charWrapper.appendChild(document.createTextNode(tnodeText.substr(i, 1))); - frag.appendChild(charWrapper); - frag.appendChild(document.createTextNode(tnodeText.substring(i + 1))); - container.replaceChild(frag, tnode); - - var result = { - top: charWrapper.offsetTop, - left: charWrapper.offsetLeft + (isSpace ? charWrapper.offsetWidth : 0), - height: charWrapper.offsetHeight - }; - - while (container.firstChild) container.removeChild(container.firstChild); - container.appendChild(tnode); - - return result; - } - - var lineText = lineNode.textContent; - var lineLength = lineText.length; - - var curNode = null; - var curChar = 0; - var curCharWithinNode = 0 - var curTop; - var curLeft; - var approxLineHeight; - var whichLine = 0; - - function nextNode() - { - var n = curNode; - if (!n) n = lineNode.firstChild; - else n = n.nextSibling; - while (n && !deepFirstChildTextNode(n)) - { - n = n.nextSibling; - } - return n; - } - - function prevNode() - { - var n = curNode; - if (!n) n = lineNode.lastChild; - else n = n.previousSibling; - while (n && !deepFirstChildTextNode(n)) - { - n = n.previousSibling; - } - return n; - } - - var seeker; - if (lineLength > 0) - { - curNode = nextNode(); - var firstCharData = charCoords(deepFirstChildTextNode(curNode), 0); - approxLineHeight = firstCharData.height; - curTop = firstCharData.top; - curLeft = firstCharData.left; - - function updateCharData(tnode, i) - { - var coords = charCoords(tnode, i); - whichLine += Math.round((coords.top - curTop) / approxLineHeight); - curTop = coords.top; - curLeft = coords.left; - } - - seeker = { - forward: function(numChars) - { - var oldChar = curChar; - var newChar = curChar + numChars; - if (newChar > (lineLength - 1)) newChar = lineLength - 1; - while (curChar < newChar) - { - var curNodeLength = deepFirstChildTextNode(curNode).length; - var toGo = curNodeLength - curCharWithinNode; - if (curChar + toGo > newChar || !nextNode()) - { - // going to next node would be too far - var n = newChar - curChar; - if (n >= toGo) n = toGo - 1; - curChar += n; - curCharWithinNode += n; - break; - } - else - { - // go to next node - curChar += toGo; - curCharWithinNode = 0; - curNode = nextNode(); - } - } - updateCharData(deepFirstChildTextNode(curNode), curCharWithinNode); - return curChar - oldChar; - }, - backward: function(numChars) - { - var oldChar = curChar; - var newChar = curChar - numChars; - if (newChar < 0) newChar = 0; - while (curChar > newChar) - { - if (curChar - curCharWithinNode <= newChar || !prevNode()) - { - // going to prev node would be too far - var n = curChar - newChar; - if (n > curCharWithinNode) n = curCharWithinNode; - curChar -= n; - curCharWithinNode -= n; - break; - } - else - { - // go to prev node - curChar -= curCharWithinNode + 1; - curNode = prevNode(); - curCharWithinNode = deepFirstChildTextNode(curNode).length - 1; - } - } - updateCharData(deepFirstChildTextNode(curNode), curCharWithinNode); - return oldChar - curChar; - }, - getVirtualLine: function() - { - return whichLine; - }, - getLeftCoord: function() - { - return curLeft; - } - }; - } - else - { - curLeft = lineNode.offsetLeft; - seeker = { - forward: function(numChars) - { - return 0; - }, - backward: function(numChars) - { - return 0; - }, - getVirtualLine: function() - { - return 0; - }, - getLeftCoord: function() - { - return curLeft; - } - }; - } - seeker.getOffset = function() - { - return curChar; - }; - seeker.getLineLength = function() - { - return lineLength; - }; - seeker.toString = function() - { - return "seeker[curChar: " + curChar + "(" + lineText.charAt(curChar) + "), left: " + seeker.getLeftCoord() + ", vline: " + seeker.getVirtualLine() + "]"; - }; - - function moveByWhile(isBackward, amount, optCondFunc, optCharLimit) - { - var charsMovedLast = null; - var hasCondFunc = ((typeof optCondFunc) == "function"); - var condFunc = optCondFunc; - var hasCharLimit = ((typeof optCharLimit) == "number"); - var charLimit = optCharLimit; - while (charsMovedLast !== 0 && ((!hasCondFunc) || condFunc())) - { - var toMove = amount; - if (hasCharLimit) - { - var untilLimit = (isBackward ? curChar - charLimit : charLimit - curChar); - if (untilLimit < toMove) toMove = untilLimit; - } - if (toMove < 0) break; - charsMovedLast = (isBackward ? seeker.backward(toMove) : seeker.forward(toMove)); - } - } - - seeker.forwardByWhile = function(amount, optCondFunc, optCharLimit) - { - moveByWhile(false, amount, optCondFunc, optCharLimit); - } - seeker.backwardByWhile = function(amount, optCondFunc, optCharLimit) - { - moveByWhile(true, amount, optCondFunc, optCharLimit); - } - seeker.binarySearch = function(condFunc) - { - // returns index of boundary between false chars and true chars; - // positions seeker at first true char, or else last char - var trueFunc = condFunc; - var falseFunc = function() - { - return !condFunc(); - }; - seeker.forwardByWhile(20, falseFunc); - seeker.backwardByWhile(20, trueFunc); - seeker.forwardByWhile(10, falseFunc); - seeker.backwardByWhile(5, trueFunc); - seeker.forwardByWhile(1, falseFunc); - return seeker.getOffset() + (condFunc() ? 0 : 1); - } - - return seeker; - } - -} - -exports.makeVirtualLineView = makeVirtualLineView; From 77cf2aafacf859b053ee2d704f6b2ce0d4df5a71 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 8 Dec 2013 17:35:11 +0100 Subject: [PATCH 18/18] [pad_modals] remove unused variables. for the hide/show functions jquery's default variables are used everywhere --- src/static/js/pad_modals.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/static/js/pad_modals.js b/src/static/js/pad_modals.js index 39094a7e..67b03662 100644 --- a/src/static/js/pad_modals.js +++ b/src/static/js/pad_modals.js @@ -20,7 +20,6 @@ * limitations under the License. */ -var padutils = require('./pad_utils').padutils; var padeditbar = require('./pad_editbar').padeditbar; var padmodals = (function() @@ -39,10 +38,10 @@ var padmodals = (function() padeditbar.toggleDropDown("connectivity"); }); }, - showOverlay: function(duration) { + showOverlay: function() { $("#overlay").show(); }, - hideOverlay: function(duration) { + hideOverlay: function() { $("#overlay").hide(); } };