mirror of
https://github.com/Codeux-Software/Textual.git
synced 2026-06-16 13:24:32 +00:00
Reorganize project
Many resources have been added to Textual with little thought for long term maintenance. This commit is an overdue overhaul of the entire project. The goals of this overhaul was to introduce as much consistency as possible to the project. Some notable changes: • Code signing identity file has moved to "Configurations/Build" • All build configuration files, including entitlements, moved to "Configurations" • Source code for the app has moved to "Sources/App" • Shared source code has moved to "Sources/Shared" • Source code for extensions have moved to "Sources/Plugins" • The project file for the app has moved along with its source code. It's recommended to use the Textual.xcworkspace workspace file. • Build scripts are no longer packaged within the project files. • Folders are now used throughout most projects instead of groups. • Removed a lot of redundant framework linking. • The preference panel sample plugin has been modified to use standard Cocoa facilities instead of those that are project specific. e.g. NSUserDefaults and NSLog() instead of TPCPreferencesUserDefaults and LogToConsole()
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
var ConversationTracking = {};
|
||||
|
||||
/* State tracking */
|
||||
ConversationTracking.trackedNicknames = [];
|
||||
|
||||
/* Core functions */
|
||||
ConversationTracking.nicknameSingleClickEventCallback = function(senderElement)
|
||||
{
|
||||
/* This is called when .sender is clicked */
|
||||
var nickname = senderElement.dataset.nickname;
|
||||
|
||||
/* Toggle status for nickname */
|
||||
var trackingIndex = ConversationTracking.trackedNicknames.indexOf(nickname);
|
||||
|
||||
if (trackingIndex >= 0) {
|
||||
ConversationTracking.trackedNicknames.splice(trackingIndex, 1);
|
||||
} else {
|
||||
ConversationTracking.trackedNicknames.push(nickname);
|
||||
}
|
||||
|
||||
/* Gather basic information */
|
||||
var documentBody = Textual.documentBodyElement();
|
||||
|
||||
var plainTextLines = documentBody.querySelectorAll('div[data-line-type="privmsg"], div[data-line-type="action"]');
|
||||
|
||||
/* Update all elements of the DOM matching conditions */
|
||||
for (var i = 0; i < plainTextLines.length; i++) {
|
||||
var lineSender = plainTextLines[i].querySelector(".sender");
|
||||
|
||||
if (lineSender && lineSender.dataset.nickname === nickname) {
|
||||
ConversationTracking.toggleSelectionStatusForSenderElement(lineSender);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ConversationTracking.updateNicknameWithNewMessage = function(lineElement)
|
||||
{
|
||||
var elementType = lineElement.dataset.lineType;
|
||||
|
||||
/* We only want to target plain text messages */
|
||||
if (elementType === "privmsg" ||
|
||||
elementType === "action" ||
|
||||
elementType === "notice")
|
||||
{
|
||||
var senderElement = lineElement.querySelector(".sender");
|
||||
|
||||
if (senderElement) {
|
||||
/* Is this a tracked nickname? */
|
||||
var nickname = senderElement.dataset.nickname;
|
||||
|
||||
if (ConversationTracking.isNicknameTracked(nickname) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Toggle status on for new message */
|
||||
ConversationTracking.toggleSelectionStatusForSenderElement(senderElement);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ConversationTracking.toggleSelectionStatusForSenderElement = function(senderElement)
|
||||
{
|
||||
var line = senderElement.lineContainer();
|
||||
|
||||
line.classList.toggle("selectedUser");
|
||||
};
|
||||
|
||||
/* Helper functions */
|
||||
ConversationTracking.isNicknameTracked = function(nickname)
|
||||
{
|
||||
if (ConversationTracking.trackedNicknames.indexOf(nickname) >= 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
/* Selection */
|
||||
Textual.currentSelection = function() /* PUBLIC */
|
||||
{
|
||||
return window.getSelection().toString();
|
||||
};
|
||||
|
||||
Textual.clearSelection = function() /* PUBLIC */
|
||||
{
|
||||
window.getSelection().empty();
|
||||
};
|
||||
|
||||
_Textual.clearSelectionAndPreventDefault = function() /* PRIVATE */
|
||||
{
|
||||
Textual.clearSelection();
|
||||
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
_Textual.recordSelection = function() /* PRIVATE */
|
||||
{
|
||||
var selectedText = Textual.currentSelection();
|
||||
|
||||
appPrivate.setSelection(selectedText);
|
||||
};
|
||||
|
||||
_Textual._selectionChangedCallback = function() /* PRIVATE */
|
||||
{
|
||||
_Textual.recordSelection();
|
||||
};
|
||||
|
||||
_Textual.copySelectionOnMouseUpEvent = function() /* PRIVATE */
|
||||
{
|
||||
if (window.event.metaKey || window.event.altKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
appPrivate.copySelectionWhenPermitted(
|
||||
function(returnValue) {
|
||||
if (returnValue) {
|
||||
Textual.clearSelection();
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/* Contextual menu management */
|
||||
_Textual.usesCustomMenuConstructor = function() /* PRIVATE */
|
||||
{
|
||||
if (app.isWebKit2() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* macOS Sierra has an Objective-C API to modify the menus in
|
||||
WebKit2 which isn't too difficult to use which means we only
|
||||
need a custom menu constructor on WebKit2 + OS X El Capitan. */
|
||||
if (typeof window.webkit.messageHandlers.displayContextMenu === "object") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
_Textual._openGenericContextualMenu = function() /* PRIVATE */
|
||||
{
|
||||
/* Do not block if target element already has a callback. */
|
||||
if (event.target.oncontextmenu !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_Textual.usesCustomMenuConstructor()) {
|
||||
event.preventDefault();
|
||||
|
||||
_Textual.recordSelection();
|
||||
|
||||
appPrivate.displayContextMenu();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.openChannelNameContextualMenu = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.setPolicyChannelName();
|
||||
|
||||
if (_Textual.usesCustomMenuConstructor()) {
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
appPrivate.displayContextMenu();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.openURLManagementContextualMenu = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.setPolicyURLAddress();
|
||||
|
||||
if (_Textual.usesCustomMenuConstructor()) {
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
appPrivate.displayContextMenu();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.openStandardNicknameContextualMenu = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.setPolicyStandardNickname();
|
||||
|
||||
if (_Textual.usesCustomMenuConstructor()) {
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
appPrivate.displayContextMenu();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.openInlineNicknameContextualMenu = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.setPolicyInlineNickname();
|
||||
|
||||
if (_Textual.usesCustomMenuConstructor()) {
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
appPrivate.displayContextMenu();
|
||||
}
|
||||
};
|
||||
|
||||
_Textual.setPolicyStandardNickname = function() /* PRIVATE */
|
||||
{
|
||||
var userNickname = event.target.dataset.nickname;
|
||||
|
||||
appPrivate.setNickname(userNickname);
|
||||
};
|
||||
|
||||
_Textual.setPolicyInlineNickname = function() /* PRIVATE */
|
||||
{
|
||||
var userNickname = event.target.textContent;
|
||||
|
||||
var userMode = event.target.dataset.mode;
|
||||
|
||||
if (userMode && userMode.length > 0 && userNickname.indexOf(userMode) === 0) {
|
||||
appPrivate.setNickname(userNickname.substring(1));
|
||||
} else {
|
||||
appPrivate.setNickname(userNickname);
|
||||
}
|
||||
};
|
||||
|
||||
_Textual.setPolicyURLAddress = function() /* PRIVATE */
|
||||
{
|
||||
appPrivate.setURLAddress(event.target.getAttribute("href"));
|
||||
};
|
||||
|
||||
_Textual.setPolicyChannelName = function() /* PRIVATE */
|
||||
{
|
||||
appPrivate.setChannelName(event.target.textContent);
|
||||
};
|
||||
|
||||
/* Double click actions */
|
||||
Textual._nicknameDoubleClickTimer = null;
|
||||
|
||||
Textual.nicknameMaybeWasDoubleClicked = function(e) /* PUBLIC */
|
||||
{
|
||||
if (Textual._nicknameDoubleClickTimer) {
|
||||
clearTimeout(Textual._nicknameDoubleClickTimer);
|
||||
|
||||
Textual._nicknameDoubleClickTimer = null;
|
||||
|
||||
Textual.nicknameDoubleClicked(e);
|
||||
} else {
|
||||
Textual._nicknameDoubleClickTimer = setTimeout(function() {
|
||||
Textual._nicknameDoubleClickTimer = null;
|
||||
|
||||
Textual.nicknameSingleClicked(e);
|
||||
}, 250);
|
||||
}
|
||||
};
|
||||
|
||||
Textual.nicknameSingleClicked = function(e) /* PUBLIC */
|
||||
{
|
||||
// API does not handle this action by default...
|
||||
};
|
||||
|
||||
Textual.channelNameDoubleClicked = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
_Textual.setPolicyChannelName();
|
||||
|
||||
appPrivate.channelNameDoubleClicked();
|
||||
};
|
||||
|
||||
Textual.nicknameDoubleClicked = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
_Textual.setPolicyStandardNickname();
|
||||
|
||||
appPrivate.nicknameDoubleClicked();
|
||||
};
|
||||
|
||||
Textual.inlineNicknameDoubleClicked = function() /* PUBLIC */
|
||||
{
|
||||
_Textual.clearSelectionAndPreventDefault();
|
||||
|
||||
_Textual.setPolicyInlineNickname();
|
||||
|
||||
appPrivate.nicknameDoubleClicked();
|
||||
};
|
||||
|
||||
/* Bind to events */
|
||||
document.addEventListener("contextmenu", _Textual._openGenericContextualMenu, false);
|
||||
|
||||
document.addEventListener("selectionchange", _Textual._selectionChangedCallback, false);
|
||||
@@ -0,0 +1,275 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
/* Loading screen */
|
||||
Textual.loadingScreenElement = function() /* PUBLIC */
|
||||
{
|
||||
return document.getElementById("loadingScreen");
|
||||
};
|
||||
|
||||
Textual.fadeOutLoadingScreen = function(bodyOp, topicOp) /* PUBLIC */
|
||||
{
|
||||
var documentBody = Textual.documentBodyElement();
|
||||
|
||||
var topicBar = Textual.topicBarElement();
|
||||
|
||||
var loadingScreen = Textual.loadingScreenElement();
|
||||
|
||||
/* Modify the opacity values of the various elements */
|
||||
loadingScreen.style.opacity = 0.00;
|
||||
|
||||
documentBody.style.opacity = bodyOp;
|
||||
|
||||
if (topicBar !== null) {
|
||||
topicBar.style.opacity = topicOp;
|
||||
}
|
||||
|
||||
/* The fade time for the loading screen depends on the CSS of the actual
|
||||
style, but there is no reason it should take more than five (5) seconds.
|
||||
We will wait that amount of time before setting the overlay to hidden.
|
||||
Setting it to hidden makes it not copiable after it is not visible. */
|
||||
setTimeout(function() {
|
||||
var loadingScreen = Textual.loadingScreenElement();
|
||||
|
||||
loadingScreen.style.display = "none";
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
/* Topic bar */
|
||||
Textual._topicBarElementReference = null; /* PRIVATE */
|
||||
|
||||
Textual.topicBarElement = function() /* PUBLIC */
|
||||
{
|
||||
if (Textual._topicBarElementReference === null) {
|
||||
Textual._topicBarElementReference = document.getElementById("topicBar");
|
||||
}
|
||||
|
||||
return Textual._topicBarElementReference;
|
||||
};
|
||||
|
||||
Textual.topicBarValue = function(asText) /* PUBLIC */
|
||||
{
|
||||
var topicBar = Textual.topicBarElement();
|
||||
|
||||
if (topicBar) {
|
||||
if (typeof asText === 'undefined' || asText === true) {
|
||||
return topicBar.textContent;
|
||||
} else {
|
||||
return topicBar.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Textual.setTopicBarValue = function(topicValue, topicValueHTML) /* PUBLIC */
|
||||
{
|
||||
var topicBar = Textual.topicBarElement();
|
||||
|
||||
if (topicBar) {
|
||||
topicBar.innerHTML = topicValueHTML;
|
||||
|
||||
Textual.topicBarValueChanged(topicValue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Textual.setTopicBarVisible = function(isVisible) /* PUBLIC */
|
||||
{
|
||||
var topicBar = Textual.topicBarElement();
|
||||
|
||||
if (topicBar) {
|
||||
if (isVisible) {
|
||||
topicBar.style.display = "";
|
||||
} else {
|
||||
topicBar.style.display = "none";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Textual.topicBarDoubleClicked = function() /* PUBLIC */
|
||||
{
|
||||
appPrivate.topicBarDoubleClicked();
|
||||
};
|
||||
|
||||
/* History indicator */
|
||||
_Textual.historyIndicatorAdd = function(templateHTML) /* PRIVATE */
|
||||
{
|
||||
_Textual.historyIndicatorRemove();
|
||||
|
||||
MessageBuffer.bufferElementAppend(templateHTML);
|
||||
|
||||
Textual.historyIndicatorAddedToView();
|
||||
};
|
||||
|
||||
_Textual.historyIndicatorRemove = function() /* PRIVATE */
|
||||
{
|
||||
var e = document.getElementById("mark");
|
||||
|
||||
if (e) {
|
||||
e.remove();
|
||||
|
||||
Textual.historyIndicatorRemovedFromView();
|
||||
}
|
||||
};
|
||||
|
||||
/* Document body */
|
||||
Textual._documentBodyElementReference = null; /* PRIVATE */
|
||||
|
||||
Textual.documentBodyElement = function() /* PUBLIC */
|
||||
{
|
||||
if (Textual._documentBodyElementReference === null) {
|
||||
Textual._documentBodyElementReference = document.getElementById("body");
|
||||
}
|
||||
|
||||
return Textual._documentBodyElementReference;
|
||||
};
|
||||
|
||||
Textual.documentHTML = function() /* PUBLIC */
|
||||
{
|
||||
return document.documentElement.innerHTML;
|
||||
};
|
||||
|
||||
/* History */
|
||||
_Textual.documentBodyAppendHistoric = function(templateHTML, lineNumbers, isReload) /* PRIVATE */
|
||||
{
|
||||
var atBottom = TextualScroller.isScrolledToBottom();
|
||||
|
||||
if (atBottom === false) {
|
||||
TextualScroller.saveRestorationFirstDataPoint();
|
||||
}
|
||||
|
||||
MessageBuffer.bufferElementPrepend(templateHTML, lineNumbers);
|
||||
|
||||
if (atBottom === false) {
|
||||
TextualScroller.saveRestorationSecondDataPoint();
|
||||
|
||||
TextualScroller.restoreScrollPosition();
|
||||
}
|
||||
};
|
||||
|
||||
/* Text */
|
||||
Textual.changeTextSizeMultiplier = function(sizeMultiplier) /* PUBLIC */
|
||||
{
|
||||
if (sizeMultiplier === 1.0) {
|
||||
document.body.style.fontSize = "";
|
||||
} else {
|
||||
document.body.style.fontSize = ((sizeMultiplier * 100.0) + "%");
|
||||
}
|
||||
};
|
||||
|
||||
/* Line numbers */
|
||||
HTMLDocument.prototype.getElementByLineNumber = function(lineNumber)
|
||||
{
|
||||
lineNumber = lineNumber.standardizedLineNumber();
|
||||
|
||||
return document.getElementById(lineNumber);
|
||||
};
|
||||
|
||||
String.prototype.standardizedLineNumber = function() /* PUBLIC */
|
||||
{
|
||||
if (this.indexOf("line-") !== 0) {
|
||||
return ("line-" + this);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
String.prototype.lineNumberContents = function(lineNumber) /* PUBLIC */
|
||||
{
|
||||
if (this.indexOf("line-") === 0) {
|
||||
return this.substr(5);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/* Given an element, find which .line element contains it. */
|
||||
Element.prototype.lineContainer = function()
|
||||
{
|
||||
var testElement = (function(element) {
|
||||
if (element.id &&
|
||||
element.id.indexOf("line-") === 0 &&
|
||||
element.classList &&
|
||||
element.classList.contains("line"))
|
||||
{
|
||||
return element;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
var line = null; /* default value */
|
||||
|
||||
/* Test this element and all its parents */
|
||||
var currentElement = this;
|
||||
|
||||
do {
|
||||
line = testElement(currentElement);
|
||||
|
||||
if (line) {
|
||||
break;
|
||||
}
|
||||
} while (currentElement = currentElement.parentElement);
|
||||
|
||||
/* Returns the line container or null */
|
||||
return line;
|
||||
};
|
||||
|
||||
Element.prototype.lineNumberContents = function()
|
||||
{
|
||||
var line = this.lineContainer();
|
||||
|
||||
if (!line) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var lineNumber = line.id;
|
||||
|
||||
return lineNumber.lineNumberContents();
|
||||
};
|
||||
@@ -0,0 +1,209 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
Textual.finishedLoadingView = false; /* PUBLIC */
|
||||
Textual.finishedLoadingHistory = false; /* PUBLIC */
|
||||
|
||||
/* State management */
|
||||
_Textual.notifyDidBecomeVisible = function() /* PRIVATE */
|
||||
{
|
||||
Textual.clearSelection();
|
||||
|
||||
document.body.dataset.visible = "true";
|
||||
};
|
||||
|
||||
_Textual.notifyDidBecomeHidden = function() /* PRIVATE */
|
||||
{
|
||||
Textual.clearSelection();
|
||||
|
||||
document.body.dataset.visible = false;
|
||||
};
|
||||
|
||||
_Textual.notifySelectionChanged = function(isSelected) /* PRIVATE */
|
||||
{
|
||||
/* Changing this attribute may change the height of the body
|
||||
because of the disappearance and reappearance of the topic.
|
||||
It is easiest for us to keep a record of where we were before
|
||||
changing this attribute, then scroll to that. */
|
||||
var scrolledToBottom = TextualScroller.isScrolledToBottom();
|
||||
|
||||
if (isSelected) {
|
||||
document.body.dataset.selected = "true";
|
||||
} else {
|
||||
document.body.dataset.selected = "false";
|
||||
}
|
||||
|
||||
if (scrolledToBottom) {
|
||||
TextualScroller.scrollToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.viewBodyDidLoadInt = function() /* PRIVATE */
|
||||
{
|
||||
console.warn("Textual.viewBodyDidLoadInt() is deprecated. Use _Textual.viewBodyDidLoad() instead.");
|
||||
|
||||
_Textual.viewBodyDidLoad();
|
||||
};
|
||||
|
||||
_Textual._viewBodyDidLoadAnimationFrame = null; /* PRIVATE */
|
||||
|
||||
_Textual.viewBodyDidLoad = function() /* PRIVATE */
|
||||
{
|
||||
/* Wait until element is available before binding to it. */
|
||||
_TextualScroller.bindToBestElement();
|
||||
|
||||
/* On styles with a dark background, a white flash occurs because there is a very
|
||||
small delay between the view being created and the background process laying out
|
||||
its contents. To work around this, Textual presents an overlay view that matches
|
||||
the background color of the style. We then request an animation frame that calls
|
||||
app.finishedLayingOutView), instructing Textual that it can destroy the overlay view. */
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
_Textual._viewBodyDidLoadAnimationFrame =
|
||||
window.requestAnimationFrame(function() {
|
||||
_Textual._viewBodyDidLoad();
|
||||
});
|
||||
} else {
|
||||
_Textual._viewBodyDidLoad();
|
||||
}
|
||||
};
|
||||
|
||||
_Textual._viewBodyDidLoad = function() /* PRIVATE */
|
||||
{
|
||||
_Textual._viewBodyDidLoadAnimationFrame = null;
|
||||
|
||||
appPrivate.finishedLayingOutView();
|
||||
|
||||
Textual.viewBodyDidLoad();
|
||||
};
|
||||
|
||||
_Textual.viewFinishedLoading = function(configuration) /* PRIVATE */
|
||||
{
|
||||
var isSelected = configuration.selected;
|
||||
var isVisible = configuration.visible;
|
||||
var isReloadingTheme = configuration.reloadingTheme;
|
||||
var textSizeMultiplier = configuration.textSizeMultiplier;
|
||||
var scrollbackLimit = configuration.scrollbackLimit;
|
||||
|
||||
_TextualScroller.createMutationObserver();
|
||||
|
||||
if (isVisible) {
|
||||
_Textual.notifyDidBecomeVisible();
|
||||
|
||||
if (isSelected) {
|
||||
_Textual.notifySelectionChanged(true);
|
||||
} else {
|
||||
_Textual.notifySelectionChanged(false);
|
||||
}
|
||||
} else {
|
||||
_Textual.notifyDidBecomeHidden();
|
||||
}
|
||||
|
||||
if (isReloadingTheme) {
|
||||
Textual.viewFinishedReload();
|
||||
} else {
|
||||
Textual.viewFinishedLoading();
|
||||
}
|
||||
|
||||
/* If this view is not visible to the user, then cancel the animation
|
||||
frame set by Textual.viewBodyDidLoadInt() because there is no use for it. */
|
||||
if (isVisible === false && isSelected === false) {
|
||||
if (_Textual._viewBodyDidLoadAnimationFrame) {
|
||||
window.cancelAnimationFrame(_Textual._viewBodyDidLoadAnimationFrame);
|
||||
|
||||
_Textual._viewBodyDidLoad();
|
||||
}
|
||||
}
|
||||
|
||||
Textual.changeTextSizeMultiplier(textSizeMultiplier);
|
||||
|
||||
if (scrollbackLimit !== 0) { // 0 = use default
|
||||
_MessageBuffer.setBufferLimit(scrollbackLimit);
|
||||
}
|
||||
};
|
||||
|
||||
_Textual.viewFinishedLoadingHistory = function() /* PRIVATE */
|
||||
{
|
||||
Textual.finishedLoadingHistory = true;
|
||||
|
||||
Textual.viewFinishedLoadingHistory();
|
||||
};
|
||||
|
||||
_Textual.messageAddedToView = function(lineNumber, fromBuffer) /* PRIVATE */
|
||||
{
|
||||
/* Allow lineNumber to be an array of line numbers or a single line number. */
|
||||
if (Array.isArray(lineNumber)) {
|
||||
for (var i = 0; i < lineNumber.length; i++) {
|
||||
Textual.messageAddedToView(lineNumber[i], fromBuffer);
|
||||
}
|
||||
} else {
|
||||
Textual.messageAddedToView(lineNumber, fromBuffer);
|
||||
}
|
||||
|
||||
appPrivate.notifyLinesAddedToView(lineNumber);
|
||||
};
|
||||
|
||||
_Textual.messageRemovedFromView = function(lineNumber) /* PRIVATE */
|
||||
{
|
||||
/* Allow lineNumber to be an array of line numbers or a single line number. */
|
||||
if (Array.isArray(lineNumber)) {
|
||||
for (var i = 0; i < lineNumber.length; i++) {
|
||||
Textual.messageRemovedFromView(lineNumber[i]);
|
||||
}
|
||||
} else {
|
||||
Textual.messageRemovedFromView(lineNumber);
|
||||
}
|
||||
|
||||
appPrivate.notifyLinesRemovedFromView(lineNumber);
|
||||
};
|
||||
|
||||
/* Events */
|
||||
_Textual._mouseUpEventCallback = function() /* PRIVATE */
|
||||
{
|
||||
_Textual.copySelectionOnMouseUpEvent();
|
||||
};
|
||||
|
||||
/* Bind to events */
|
||||
document.addEventListener("mouseup", _Textual._mouseUpEventCallback, false);
|
||||
@@ -0,0 +1,509 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
/* ************************************************** */
|
||||
/* Document Prototypes */
|
||||
/* ************************************************** */
|
||||
|
||||
HTMLDocument.prototype.getInlineMediaById = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
if (mediaId.indexOf("inlineMedia-") !== 0) {
|
||||
mediaId = ("inlineMedia-" + mediaId);
|
||||
}
|
||||
|
||||
return this.getElementById(mediaId);
|
||||
};
|
||||
|
||||
HTMLDocument.prototype.getInlineMediaAnchorById = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
return document.body.querySelector("a[data-ilm-anchor=\"" + mediaId + "\"]");
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Media Prototype */
|
||||
/* ************************************************** */
|
||||
|
||||
var InlineMediaPrototype = function() {
|
||||
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype._isSubclass = function()
|
||||
{
|
||||
return (Object.getPrototypeOf(this) !== InlineMediaPrototype.prototype);
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.showOnClick = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
this.show(mediaId);
|
||||
|
||||
return false; // Do not perform navigation
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.hideOnClick = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
this.hide(mediaId);
|
||||
|
||||
return false; // Do not perform navigation
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.toggleOnClick = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
if (this.isSafeToPerformToggle() === false) {
|
||||
console.log("Cancelled toggling inline media because of isSafeToPerformToggle() condition.");
|
||||
|
||||
return true; // Perform navigation
|
||||
}
|
||||
|
||||
this.toggle(mediaId);
|
||||
|
||||
return false; // Do not perform navigation
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.show = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
this.changeVisiblity(mediaId, "show");
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.hide = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
this.changeVisiblity(mediaId, "hide");
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.toggle = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
this.changeVisiblity(mediaId, "toggle");
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.changeVisiblity = function(mediaId, display) /* PRIVATE */
|
||||
{
|
||||
var mediaElement = document.getInlineMediaById(mediaId);
|
||||
|
||||
/* Determine whether we will hide the media or show it */
|
||||
var displayNone;
|
||||
|
||||
if (display === "hide") {
|
||||
displayNone = true;
|
||||
} else if (display === "show") {
|
||||
displayNone = false;
|
||||
} else if (display === "toggle") {
|
||||
displayNone = ( mediaElement &&
|
||||
mediaElement.style.display !== "none");
|
||||
} else {
|
||||
throw "Invalid 'display' value";
|
||||
}
|
||||
|
||||
/* ********************************************* */
|
||||
|
||||
/* The logic for each type of action is defined below as a
|
||||
self contained function. This makes it easier to maintain. */
|
||||
|
||||
/* Remove media */
|
||||
var _changeVisiblityByRemoving = (function()
|
||||
{
|
||||
if (this.willRemoveMedia(mediaId, mediaElement) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaElement.remove();
|
||||
|
||||
this.didRemoveMedia(mediaId);
|
||||
}).bind(this);
|
||||
|
||||
/* Show media */
|
||||
var _changeVisiblityByDisplaying = (function()
|
||||
{
|
||||
if (this.willShowMedia(mediaId, mediaElement) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaElement.style.display = "";
|
||||
|
||||
this.didShowMedia(mediaId, mediaElement);
|
||||
}).bind(this);
|
||||
|
||||
/* Load media */
|
||||
var _changeVisiblityByLoading = (function()
|
||||
{
|
||||
var anchor = document.getInlineMediaAnchorById(mediaId);
|
||||
|
||||
if (!anchor) {
|
||||
console.error("Failed to find inline media anchor that matches ID: " + mediaId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!anchor.dataset.ilmLoading) {
|
||||
anchor.dataset.ilmLoading = "true";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.willLoadMedia(mediaId) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
var address = anchor.href;
|
||||
|
||||
var lineNumber = anchor.lineNumberContents();
|
||||
|
||||
var index = this.indexOfMediaAnchor(anchor);
|
||||
|
||||
appPrivate.loadInlineMedia(address, mediaId, lineNumber, index);
|
||||
}).bind(this);
|
||||
|
||||
/* ********************************************* */
|
||||
|
||||
if (displayNone)
|
||||
{
|
||||
/* When hiding media, we remove it completely from the DOM.
|
||||
The onclick event for toggling media will always exist in
|
||||
the anchor which means the user can shift click that to load
|
||||
the media again if they so choose. */
|
||||
|
||||
_changeVisiblityByRemoving();
|
||||
}
|
||||
else if (mediaElement)
|
||||
{
|
||||
/* If the media already exists, then we have nothing
|
||||
to do here other than set the display property. */
|
||||
|
||||
_changeVisiblityByDisplaying();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We aren't hiding the media and the media does not
|
||||
already exist in the DOM, which means we need to fire
|
||||
off a request to load it. */
|
||||
|
||||
_changeVisiblityByLoading();
|
||||
}
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.isSafeToPerformToggle = function() /* PUBLIC */
|
||||
{
|
||||
/* This logic is placed in a function to leave room for expansion. */
|
||||
|
||||
return (window.event.shiftKey === true);
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.willLoadMedia = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.didLoadMedia = function(mediaId, mediaElement)
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.didLoadMediaWithPayload = function(payload) /* PUBLIC */
|
||||
{
|
||||
var mediaId = payload.uniqueIdentifier;
|
||||
|
||||
this._didLoadMediaModifyAnchor(mediaId);
|
||||
|
||||
var mediaElement = document.getInlineMediaById(mediaId);
|
||||
|
||||
this.didLoadMedia(mediaId, mediaElement);
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype._didLoadMediaModifyAnchor = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
var anchor = document.getInlineMediaAnchorById(mediaId);
|
||||
|
||||
if (!anchor) {
|
||||
console.error("Failed to find inline media anchor that matches ID: " + mediaId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Modify attributes */
|
||||
if (anchor.dataset.ilmLoading) {
|
||||
delete anchor.dataset.ilmLoading;
|
||||
}
|
||||
|
||||
/* Replace onclick event with one for current class */
|
||||
if (this._isSubclass()) {
|
||||
anchor.onclick = (function() {
|
||||
return this.toggleOnClick(mediaId);
|
||||
}).bind(this);
|
||||
}
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.willShowMedia = function(mediaId, mediaElement) /* PUBLIC */
|
||||
{
|
||||
mediaElement.prepareForMutation();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.didShowMedia = function(mediaId, mediaElement) /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.willRemoveMedia = function(mediaId, mediaElement) /* PUBLIC */
|
||||
{
|
||||
mediaElement.prepareForMutation();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.didRemoveMedia = function(mediaId) /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.entrypoint = function(payload, insertHTMLCallback)
|
||||
{
|
||||
document.prepareForMutation();
|
||||
|
||||
insertHTMLCallback(payload.html);
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.indexOfMedia = function(mediaId)
|
||||
{
|
||||
var anchor = document.getInlineMediaAnchorById(mediaId);
|
||||
|
||||
if (!anchor) {
|
||||
console.error("Failed to find inline media anchor that matches ID: " + mediaId);
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return this.indexOfMediaAnchor(anchor);
|
||||
};
|
||||
|
||||
InlineMediaPrototype.prototype.indexOfMediaAnchor = function(anchor)
|
||||
{
|
||||
var allAnchors = anchor.parentElement.getElementsByTagName("a");
|
||||
|
||||
var index = Array.prototype.indexOf.call(allAnchors, anchor);
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Media Public Interface */
|
||||
/* ************************************************** */
|
||||
|
||||
var InlineMedia = Object.create(InlineMediaPrototype.prototype);
|
||||
|
||||
/* ************************************************** */
|
||||
/* Media Private Interface */
|
||||
/* ************************************************** */
|
||||
|
||||
var _InlineMediaLoader = {};
|
||||
|
||||
_InlineMediaLoader._loadedStyleResources = new Array(); /* PRIVATE */
|
||||
_InlineMediaLoader._loadedScriptResources = new Array(); /* PRIVATE */
|
||||
|
||||
_InlineMediaLoader.processPayload = function(payload) /* PRIVATE */
|
||||
{
|
||||
/* Load CSS resources */
|
||||
var styleResources = payload.styleResources;
|
||||
|
||||
if (Array.isArray(styleResources)) {
|
||||
for (var i = 0; i < styleResources.length; i++) {
|
||||
var file = styleResources[i];
|
||||
|
||||
if (_InlineMediaLoader._loadedStyleResources.indexOf(file) < 0) {
|
||||
_InlineMediaLoader._loadedStyleResources.push(file);
|
||||
|
||||
Textual.includeStyleResourceFile(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load JavaScript resources */
|
||||
var scriptResources = payload.scriptResources;
|
||||
|
||||
if (Array.isArray(scriptResources)) {
|
||||
for (var i = 0; i < scriptResources.length; i++) {
|
||||
var file = scriptResources[i];
|
||||
|
||||
if (_InlineMediaLoader._loadedScriptResources.indexOf(file) < 0) {
|
||||
_InlineMediaLoader._loadedScriptResources.push(file);
|
||||
|
||||
Textual.includeScriptResourceFile(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert HTML */
|
||||
var entrypoint = payload.entrypoint;
|
||||
|
||||
if (typeof entrypoint === "string" &&
|
||||
entrypoint.length > 0 &&
|
||||
entrypoint !== "InlineMedia") /* Don't allow module to use this */
|
||||
{
|
||||
_InlineMediaLoader.ppStep2WithEntrypoint(payload);
|
||||
} else {
|
||||
_InlineMediaLoader.ppStep2WithoutEntrypoint(payload);
|
||||
}
|
||||
};
|
||||
|
||||
_InlineMediaLoader.ppStep2WithoutEntrypoint = function(payload) /* PRIVATE */
|
||||
{
|
||||
_InlineMediaLoader.ppStep3(InlineMedia, payload, null);
|
||||
};
|
||||
|
||||
_InlineMediaLoader.ppStep2WithEntrypoint = function(payload) /* PRIVATE */
|
||||
{
|
||||
var callToEntrypoint = (function(i) {
|
||||
try {
|
||||
var entrypoint = window[payload.entrypoint];
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
/* If the entrypoint exists as an object already,
|
||||
then we call out to it and exit. */
|
||||
if (entrypoint && typeof entrypoint === "object") {
|
||||
entrypoint.entrypoint(
|
||||
payload.entrypointPayload,
|
||||
|
||||
(function(html) {
|
||||
_InlineMediaLoader.ppStep3(entrypoint, payload, html);
|
||||
})
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the entrypoint does not exist as an object yet,
|
||||
then we loop this function several times until it is
|
||||
one (script resource is loading), or until we exhaust
|
||||
the tries we are willing to take. */
|
||||
if (i === 100) { // 10 seconds
|
||||
console.error("Failed to process payload because entrypoint is not an object.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout((function() {
|
||||
callToEntrypoint(i + 1);
|
||||
}), 100); // ms
|
||||
});
|
||||
|
||||
callToEntrypoint(0);
|
||||
};
|
||||
|
||||
_InlineMediaLoader.ppStep3 = function(entrypoint, payload, html) /* PRIVATE */
|
||||
{
|
||||
/* The entrypoint function for subclasses is expected
|
||||
to call prepareForMutation() when it thinks is best.
|
||||
When the entrypoint is InlineMedia, the entrypoint
|
||||
function is never called. We therefore call it here
|
||||
when that is the entrypoint. */
|
||||
if (entrypoint === InlineMedia) {
|
||||
document.prepareForMutation();
|
||||
}
|
||||
|
||||
/* Insert HTML */
|
||||
_InlineMediaLoader.insertPayload(payload, html);
|
||||
|
||||
/* Inform delegate */
|
||||
entrypoint.didLoadMediaWithPayload(payload);
|
||||
};
|
||||
|
||||
_InlineMediaLoader.insertPayload = function(payload, html) /* PRIVATE */
|
||||
{
|
||||
var lineNumber = payload.lineNumber;
|
||||
|
||||
var line = document.getElementByLineNumber(lineNumber);
|
||||
|
||||
if (!line) {
|
||||
console.error("Failed to find line that matches ID: " + lineNumber);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var mediaContainer = line.querySelector(".inlineMediaContainer");
|
||||
|
||||
if (!mediaContainer) {
|
||||
console.warning("The template for this style appears to be missing a span with the class" +
|
||||
"'inlineMediaContainer' — please fix this to support inline media.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Validate HTML */
|
||||
if (html === null) {
|
||||
html = payload.html;
|
||||
}
|
||||
|
||||
if (html.length === 0) {
|
||||
console.error("HTML is empty");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Given index of this item, find item before that index
|
||||
to insert the HTML at, or insert at end of container. */
|
||||
var index = payload.index;
|
||||
|
||||
if (index === 0) {
|
||||
/* Insert at beginning */
|
||||
mediaContainer.insertAdjacentHTML("afterbegin", html);
|
||||
} else {
|
||||
var childIndex = (index - 1);
|
||||
var childNode = null;
|
||||
var childNodes = mediaContainer.children;
|
||||
|
||||
if (childNodes.length > childIndex) {
|
||||
childNode = childNodes[childIndex];
|
||||
}
|
||||
|
||||
if (childNode) {
|
||||
childNode.insertAdjacentHTML("afterend", html);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Insert at end */
|
||||
mediaContainer.insertAdjacentHTML("beforeend", html);
|
||||
}
|
||||
};
|
||||
+846
@@ -0,0 +1,846 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
var MessageBuffer = {};
|
||||
var _MessageBuffer = {};
|
||||
|
||||
/* ************************************************** */
|
||||
/* State Tracking */
|
||||
/* ************************************************** */
|
||||
|
||||
/* The number of elements in the buffer.
|
||||
This count only includes lines (messages). Not other
|
||||
items that the style may insert into the buffer. */
|
||||
_MessageBuffer._bufferCurrentSize = 0; /* PRIVATE */
|
||||
|
||||
/* When old messages are NOT being loaded, this
|
||||
is the number of elements we want to keep. */
|
||||
_MessageBuffer._bufferSizeSoftLimitDefault = 200; /* PRIVATE */
|
||||
_MessageBuffer._bufferSizeSoftLimit = _MessageBuffer._bufferSizeSoftLimitDefault; /* PRIVATE */
|
||||
|
||||
/* When old messages are being loaded, this
|
||||
is the number of elements we want to keep. */
|
||||
_MessageBuffer._bufferSizeHardLimitDefault = 1000; /* PRIVATE */
|
||||
_MessageBuffer._bufferSizeHardLimit = _MessageBuffer._bufferSizeHardLimitDefault; /* PRIVATE */
|
||||
|
||||
/* The number of lines to fetch when loading old messages.
|
||||
When old lines are fetched, the number of lines returned
|
||||
are also removed from the relevant buffer. */
|
||||
_MessageBuffer._loadMessagesBatchSize = 200; /* PRIVATE */
|
||||
|
||||
/* _MessageBuffer._loadMessages() sets the following properties
|
||||
when it performs an action. These proeprties are not used for
|
||||
anything other than state tracking. If false, new messages are
|
||||
loaded, else the event is ignored. */
|
||||
/* The user can scroll downward while messages are still being
|
||||
loaded from scrolling upward. Therefore, we use a separate
|
||||
property to keep track of each type of load. */
|
||||
_MessageBuffer._loadingMessagesBeforeLineDuringScroll = false; /* PRIVATE */
|
||||
_MessageBuffer._loadingMessagesAfterLineDuringScroll = false; /* PRIVATE */
|
||||
|
||||
/* Set to true once we have loaded all old messages. */
|
||||
_MessageBuffer._bufferTopIsComplete = false; /* PRIVATE */
|
||||
_MessageBuffer._bufferBottomIsComplete = true; /* PRIVATE */
|
||||
|
||||
/* _MessageBuffer._jumpToLine() sets the following property
|
||||
when it performs an action. */
|
||||
_MessageBuffer._loadingMessagesDuringJump = false; /* PRIVATE */
|
||||
|
||||
/* ************************************************** */
|
||||
/* Line Management */
|
||||
/* ************************************************** */
|
||||
|
||||
MessageBuffer.firstLineInBuffer = function(buffer) /* PUBLIC */
|
||||
{
|
||||
var lines = buffer.querySelectorAll("div.line[id^='line-']");
|
||||
|
||||
return lines[0];
|
||||
};
|
||||
|
||||
MessageBuffer.lastLineInBuffer = function(buffer) /* PUBLIC */
|
||||
{
|
||||
var lines = buffer.querySelectorAll("div.line[id^='line-']");
|
||||
|
||||
return lines[(lines.length - 1)];
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Main Buffer */
|
||||
/* ************************************************** */
|
||||
|
||||
_MessageBuffer._bufferElementReference = null; /* PRIVATE */
|
||||
|
||||
MessageBuffer.bufferElement = function() /* PUBLIC */
|
||||
{
|
||||
if (_MessageBuffer._bufferElementReference === null) {
|
||||
_MessageBuffer._bufferElementReference = document.getElementById("messageBuffer");
|
||||
}
|
||||
|
||||
return _MessageBuffer._bufferElementReference;
|
||||
};
|
||||
|
||||
MessageBuffer.bufferElementPrepend = function(html, lineNumbers) /* PUBLIC */
|
||||
{
|
||||
_MessageBuffer.bufferElementInsert("afterbegin", html, lineNumbers);
|
||||
};
|
||||
|
||||
MessageBuffer.bufferElementAppend = function(html, lineNumbers) /* PUBLIC */
|
||||
{
|
||||
_MessageBuffer.bufferElementInsert("beforeend", html, lineNumbers);
|
||||
};
|
||||
|
||||
_MessageBuffer.bufferElementInsert = function(placement, html, lineNumbers) /* PRIVATE */
|
||||
{
|
||||
/* Do not append to bottom if bottom does not reflect
|
||||
the most recent state of the buffer. */
|
||||
if (_MessageBuffer._bufferBottomIsComplete === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = MessageBuffer.bufferElement();
|
||||
|
||||
buffer.prepareForMutation();
|
||||
|
||||
buffer.insertAdjacentHTML(placement, html);
|
||||
|
||||
if (lineNumbers) {
|
||||
_MessageBuffer._bufferCurrentSize += lineNumbers.length;
|
||||
|
||||
_MessageBuffer.resizeBufferIfNeeded();
|
||||
|
||||
try {
|
||||
_Textual.messageAddedToView(lineNumbers, false);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Buffer Size Management */
|
||||
/* ************************************************** */
|
||||
|
||||
MessageBuffer.noteMessageRemovedFromBuffer = function()
|
||||
{
|
||||
_MessageBuffer._adjustCurrentBufferSize(-1);
|
||||
};
|
||||
|
||||
MessageBuffer.noteMessagesRemovedFromBuffer = function(numberRemoved)
|
||||
{
|
||||
_MessageBuffer._adjustCurrentBufferSize(-1 * numberRemoved);
|
||||
};
|
||||
|
||||
_MessageBuffer._adjustCurrentBufferSize = function(byHowMuch)
|
||||
{
|
||||
console.log("Adjusting buffer by: " + byHowMuch);
|
||||
|
||||
var newSize = (_MessageBuffer._bufferCurrentSize + byHowMuch);
|
||||
|
||||
if (newSize < 0) {
|
||||
newSize = 0;
|
||||
} else if (newSize > _MessageBuffer._bufferSizeHardLimit) {
|
||||
newSize = _MessageBuffer._bufferSizeHardLimit;
|
||||
}
|
||||
|
||||
_MessageBuffer._bufferCurrentSize = newSize;
|
||||
|
||||
console.log("Buffer adjusted to: " + newSize);
|
||||
};
|
||||
|
||||
/* Allow user to set a custom buffer limit */
|
||||
_MessageBuffer.setBufferLimit = function(limit) /* PRIVATE */
|
||||
{
|
||||
if (limit < 100 || limit > 50000) {
|
||||
_MessageBuffer._bufferSizeSoftLimit = _MessageBuffer._bufferSizeSoftLimitDefault;
|
||||
_MessageBuffer._bufferSizeHardLimit = _MessageBuffer._bufferSizeHardLimitDefault;
|
||||
} else {
|
||||
_MessageBuffer._bufferSizeSoftLimit = limit;
|
||||
_MessageBuffer._bufferSizeHardLimit = limit;
|
||||
}
|
||||
};
|
||||
|
||||
/* Determine whether buffer should be resized depending on status. */
|
||||
_MessageBuffer.resizeBufferIfNeeded = function() /* PRIVATE */
|
||||
{
|
||||
/* We remove lines under the conditions:
|
||||
1. Size limit must be exceeded.
|
||||
2. When user is not scrolled, we remove from the top of the buffer.
|
||||
3. When user is scrolled below 50% of the scrollable area, then we
|
||||
remove from the bottom of the buffer.
|
||||
4. When user is scrolled above 50% of the scrollable area, then we
|
||||
remove form the top of the buffer. */
|
||||
|
||||
/* Enforce soft limit for #2 */
|
||||
if (_MessageBuffer.scrolledToBottomOfBuffer()) {
|
||||
_MessageBuffer.enforceSoftLimit(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Enforce hard limit for #3 and #4 */
|
||||
var scrollPercent = TextualScroller.percentScrolled();
|
||||
|
||||
var removeFromTop = (scrollPercent > 50.0);
|
||||
|
||||
_MessageBuffer.enforceHardLimit(removeFromTop);
|
||||
};
|
||||
|
||||
/* Given number of lines added: enforce limit and remove from top or bottom. */
|
||||
_MessageBuffer.enforceSoftLimit = function(fromTop) /* PRIVATE */
|
||||
{
|
||||
_MessageBuffer.enforceLimit(_MessageBuffer._bufferSizeSoftLimit, fromTop);
|
||||
};
|
||||
|
||||
_MessageBuffer.enforceHardLimit = function(fromTop) /* PRIVATE */
|
||||
{
|
||||
_MessageBuffer.enforceLimit(_MessageBuffer._bufferSizeHardLimit, fromTop);
|
||||
};
|
||||
|
||||
_MessageBuffer.enforceLimit = function(limit, fromTop) /* PRIVATE */
|
||||
{
|
||||
var numberToRemove = (_MessageBuffer._bufferCurrentSize - limit);
|
||||
|
||||
if (numberToRemove <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
_MessageBuffer.resizeBuffer(numberToRemove, fromTop);
|
||||
};
|
||||
|
||||
_MessageBuffer.resizeBuffer = function(numberToRemove, fromTop) /* PRIVATE */
|
||||
{
|
||||
if (numberToRemove <= 0) {
|
||||
throw "Silly number to remove";
|
||||
}
|
||||
|
||||
var lineNumbers = new Array();
|
||||
|
||||
var buffer = MessageBuffer.bufferElement();
|
||||
|
||||
buffer.prepareForMutation();
|
||||
|
||||
var numberRemoved = 0;
|
||||
|
||||
/* To avoid an infinite loop by never having a
|
||||
firstChild or lastChild that is a line, we use
|
||||
siblings and break when there are none left. */
|
||||
var currentElement = null;
|
||||
var nextElement = null;
|
||||
|
||||
do {
|
||||
if (currentElement === null) {
|
||||
if (fromTop) {
|
||||
currentElement = buffer.firstChild;
|
||||
} else {
|
||||
currentElement = buffer.lastChild;
|
||||
}
|
||||
} else {
|
||||
currentElement = nextElement;
|
||||
}
|
||||
|
||||
if (currentElement === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (fromTop) {
|
||||
nextElement = currentElement.nextElementSibling;
|
||||
} else {
|
||||
nextElement = currentElement.previousElementSibling;
|
||||
}
|
||||
|
||||
var elementId = currentElement.id;
|
||||
|
||||
if (elementId && elementId.indexOf("line-") === 0) {
|
||||
/* We wait until the next line element before
|
||||
exiting loop so that we can remove markers or
|
||||
anything related to lines that were removed. */
|
||||
if (numberRemoved >= numberToRemove) {
|
||||
break;
|
||||
}
|
||||
|
||||
lineNumbers.push(elementId);
|
||||
|
||||
numberRemoved += 1;
|
||||
}
|
||||
|
||||
currentElement.remove();
|
||||
} while (true); // lol, I know.
|
||||
|
||||
if (fromTop) {
|
||||
_MessageBuffer._bufferTopIsComplete = false;
|
||||
} else {
|
||||
_MessageBuffer._bufferBottomIsComplete = false;
|
||||
}
|
||||
|
||||
var lineNumbersCount = lineNumbers.length;
|
||||
|
||||
if (lineNumbersCount > 0) {
|
||||
_MessageBuffer._bufferCurrentSize -= lineNumbersCount;
|
||||
|
||||
_Textual.messageRemovedFromView(lineNumbers);
|
||||
}
|
||||
|
||||
console.log("Removed " + lineNumbersCount + " lines from buffer");
|
||||
};
|
||||
|
||||
/* Timer set once user scrolls back to the bottom. */
|
||||
/* Timer is used in case user scrolls back up shortly after. */
|
||||
_MessageBuffer._bufferHardLimitResizeTimer = null; /* PRIVATE */
|
||||
|
||||
_MessageBuffer.cancelHardLimitResize = function() /* PRIVATE */
|
||||
{
|
||||
if (_MessageBuffer._bufferHardLimitResizeTimer === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(_MessageBuffer._bufferHardLimitResizeTimer);
|
||||
|
||||
_MessageBuffer._bufferHardLimitResizeTimer = null;
|
||||
};
|
||||
|
||||
_MessageBuffer.scheduleHardLimitResize = function() /* PRIVATE */
|
||||
{
|
||||
if (_MessageBuffer._bufferHardLimitResizeTimer !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do not create timer if we are scrolling programmatically */
|
||||
if (_MessageBuffer._loadingMessagesDuringJump) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* No need to create timer if we haven't exceeded hard limit. */
|
||||
if (_MessageBuffer._bufferCurrentSize <= _MessageBuffer._bufferSizeSoftLimit) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do not create timer if we aren't at the true bottom. */
|
||||
if (_MessageBuffer.scrolledToBottomOfBuffer() === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create timer */
|
||||
_MessageBuffer._bufferHardLimitResizeTimer =
|
||||
setTimeout(function() {
|
||||
console.log("Buffer hard limit resize timer fired");
|
||||
|
||||
var numberToRemove = (_MessageBuffer._bufferCurrentSize - _MessageBuffer._bufferSizeSoftLimit);
|
||||
|
||||
if (numberToRemove <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
_MessageBuffer.resizeBuffer(numberToRemove, true);
|
||||
|
||||
_MessageBuffer._bufferHardLimitResizeTimer = null;
|
||||
}, 5000);
|
||||
|
||||
console.log("Buffer hard limit resize timer started");
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Load Messages */
|
||||
/* ************************************************** */
|
||||
|
||||
/* This function picks the best line to load old messages next to. */
|
||||
_MessageBuffer.loadMessagesDuringScroll = function(before) /* PRIVATE */
|
||||
{
|
||||
/* _MessageBuffer._loadMessages() is only called during scroll events by
|
||||
the user. We keep track of a request is already active then so that we
|
||||
do not keep sending them out while the user waits for one to finish. */
|
||||
if (_MessageBuffer._loadingMessagesDuringJump) {
|
||||
console.log("Cancelled request to load messages because another request is active");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (before)
|
||||
{
|
||||
if (Textual.finishedLoadingHistory === false) {
|
||||
console.log("Cancelled request to load messages above line because history isn't loaded");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_MessageBuffer._loadingMessagesBeforeLineDuringScroll) {
|
||||
console.log("Cancelled request to load messages above line because another request is active");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_MessageBuffer._bufferTopIsComplete) {
|
||||
console.log("Cancelled request to load messages because there is nothing new to load");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else // before
|
||||
{
|
||||
if (_MessageBuffer._loadingMessagesAfterLineDuringScroll) {
|
||||
console.log("Cancelled request to load messages below line because another request is active");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_MessageBuffer._bufferBottomIsComplete) {
|
||||
console.log("Cancelled request to load messages because there is nothing new to load");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find first line */
|
||||
var buffer = MessageBuffer.bufferElement();
|
||||
|
||||
var line = null;
|
||||
|
||||
if (before) {
|
||||
line = MessageBuffer.firstLineInBuffer(buffer);
|
||||
} else {
|
||||
line = MessageBuffer.lastLineInBuffer(buffer);
|
||||
}
|
||||
|
||||
/* There is nothing in either buffer */
|
||||
if (line === null) {
|
||||
console.log("No line to load from");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Load messages */
|
||||
if (before) {
|
||||
_MessageBuffer._loadingMessagesBeforeLineDuringScroll = true;
|
||||
} else {
|
||||
_MessageBuffer._loadingMessagesAfterLineDuringScroll = true;
|
||||
}
|
||||
|
||||
var lineNumberContents = line.id.lineNumberContents();
|
||||
|
||||
_MessageBuffer.loadMessagesDuringScrollWithPayload(
|
||||
{
|
||||
"before" : before,
|
||||
"line" : line,
|
||||
"lineNumberContents" : lineNumberContents
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/* Given a line we want to load old messages next to, we do so. */
|
||||
_MessageBuffer.loadMessagesDuringScrollWithPayload = function(requestPayload) /* PRIVATE */
|
||||
{
|
||||
var before = requestPayload.before;
|
||||
var line = requestPayload.line;
|
||||
var lineNumberContents = requestPayload.lineNumberContents;
|
||||
|
||||
/* Define logic that will be performed when
|
||||
are are ready to load the messages. */
|
||||
var loadMessagesLogic = (function() {
|
||||
var postflightCallback = (function(renderedMessages) {
|
||||
requestPayload.renderedMessages = renderedMessages;
|
||||
|
||||
_MessageBuffer.loadMessagesDuringScrollWithPayloadPostflight(requestPayload);
|
||||
|
||||
_MessageBuffer.removeLoadingIndicator(line);
|
||||
});
|
||||
|
||||
console.log("Loading messages before (" + before + ") line " + lineNumberContents);
|
||||
|
||||
if (before) {
|
||||
appPrivate.renderMessagesBefore(
|
||||
lineNumberContents,
|
||||
_MessageBuffer._loadMessagesBatchSize,
|
||||
postflightCallback
|
||||
);
|
||||
} else {
|
||||
appPrivate.renderMessagesAfter(
|
||||
lineNumberContents,
|
||||
_MessageBuffer._loadMessagesBatchSize,
|
||||
postflightCallback
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/* Present loading indicator then trigger logic. */
|
||||
_MessageBuffer.addLoadingIndicator(before, line, loadMessagesLogic);
|
||||
};
|
||||
|
||||
/* Postflight for loading old messages */
|
||||
_MessageBuffer.loadMessagesDuringScrollWithPayloadPostflight = function(requestPayload) /* PRIVATE */
|
||||
{
|
||||
/* Payload state */
|
||||
var before = requestPayload.before;
|
||||
var line = requestPayload.line;
|
||||
var renderedMessages = requestPayload.renderedMessages;
|
||||
|
||||
var lineNumbers = null;
|
||||
var html = null;
|
||||
|
||||
/* Perform logging */
|
||||
var renderedMessagesCount = renderedMessages.length;
|
||||
|
||||
console.log("Request to load messages for " + line.id + " returned " + renderedMessagesCount + " results");
|
||||
|
||||
if (renderedMessagesCount > 0) {
|
||||
/* Array which will house every line number that was loaded.
|
||||
The style needs this information so it can perform whatever action. */
|
||||
lineNumbers = new Array();
|
||||
|
||||
/* Array which will house every segment of HTML to append. */
|
||||
html = new Array();
|
||||
|
||||
/* Process result */
|
||||
for (var i = 0; i < renderedMessagesCount; i++) {
|
||||
var renderedMessage = renderedMessages[i];
|
||||
|
||||
var lineNumber = renderedMessage.lineNumber;
|
||||
|
||||
if (lineNumber) {
|
||||
lineNumbers.push(renderedMessage.lineNumber);
|
||||
}
|
||||
|
||||
html.push(renderedMessage.html);
|
||||
}
|
||||
|
||||
/* Append HTML */
|
||||
var htmlString = html.join("");
|
||||
|
||||
if (before) {
|
||||
line.prepareForMutation();
|
||||
|
||||
line.insertAdjacentHTML('beforebegin', htmlString);
|
||||
} else {
|
||||
line.insertAdjacentHTML('afterend', htmlString);
|
||||
}
|
||||
|
||||
_MessageBuffer._bufferCurrentSize += lineNumbers.length;
|
||||
} // renderedMessagesCount > 0
|
||||
|
||||
/* If the number of results is less than our batch size,
|
||||
then we can probably make a best guess that we have loaded
|
||||
all the old messages that are available. */
|
||||
if (renderedMessagesCount < _MessageBuffer._loadMessagesBatchSize) {
|
||||
if (before) {
|
||||
_MessageBuffer._bufferTopIsComplete = true;
|
||||
} else {
|
||||
_MessageBuffer._bufferBottomIsComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (renderedMessagesCount > 0) {
|
||||
/* Enforce size limit. This function expects the count to already be
|
||||
incremented which is why we call it AFTER the append. */
|
||||
/* Value of before is reversed because we want to remove from the
|
||||
opposite of where we added. */
|
||||
_MessageBuffer.enforceHardLimit(!before);
|
||||
|
||||
/* Cancel any mutations already queued so that we don't scroll. */
|
||||
/* Place after resizeBuffer() because that triggers a mutation. */
|
||||
line.cancelMutation();
|
||||
|
||||
/* Post line numbers so style can do something with them. */
|
||||
try {
|
||||
_Textual.messageAddedToView(lineNumbers, true);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
/* Scroll line into view */
|
||||
if (before) {
|
||||
line.scrollIntoViewAlignTop();
|
||||
} else {
|
||||
line.scrollIntoViewAlignBottom();
|
||||
}
|
||||
} // renderedMessagesCount > 0
|
||||
|
||||
/* Toggle automatic scrolling */
|
||||
/* Call after resize so that it has latest state of bottom. */
|
||||
_MessageBuffer.toggleAutomaticScrolling();
|
||||
|
||||
/* Flush state */
|
||||
if (before) {
|
||||
_MessageBuffer._loadingMessagesBeforeLineDuringScroll = false;
|
||||
} else {
|
||||
_MessageBuffer._loadingMessagesAfterLineDuringScroll = false;
|
||||
}
|
||||
};
|
||||
|
||||
_MessageBuffer.loadMessagesWithJump = function(lineNumber, callbackFunction) /* PRIVATE */
|
||||
{
|
||||
/* Safety checks */
|
||||
if (_MessageBuffer._loadingMessagesDuringJump) {
|
||||
console.log("Cancelled request to load messages because another request is active");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Textual.finishedLoadingHistory === false) {
|
||||
console.log("Cancelled request to load messages because history isn't loaded");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_MessageBuffer._loadingMessagesBeforeLineDuringScroll ||
|
||||
_MessageBuffer._loadingMessagesAfterLineDuringScroll)
|
||||
{
|
||||
console.log("Cancelled request to load messages because another request is active");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_MessageBuffer._bufferTopIsComplete &&
|
||||
_MessageBuffer._bufferBottomIsComplete)
|
||||
{
|
||||
console.log("Cancelled request to load messages because there is nothing new to load");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* This function may be called without scrolling which means we
|
||||
should cancel the resize timer. */
|
||||
_MessageBuffer.cancelHardLimitResize();
|
||||
|
||||
/* The line does not exist in the buffer, which means we have to
|
||||
load it. When we load the message, we also load X number of messages
|
||||
above it and X number of messages below it. */
|
||||
/* When jumping, we do not use the message buffer loading indicator
|
||||
because the user does not require a visual indicator. */
|
||||
_MessageBuffer._loadingMessagesDuringJump = true;
|
||||
|
||||
var lineNumberContents = lineNumber.lineNumberContents();
|
||||
|
||||
var requestPayload = {
|
||||
"lineNumberContents" : lineNumberContents,
|
||||
"lineNumberStandardized" : lineNumber,
|
||||
"callbackFunction" : callbackFunction
|
||||
};
|
||||
|
||||
console.log("Loading line " + lineNumberContents);
|
||||
|
||||
appPrivate.renderMessageWithSiblings(
|
||||
lineNumberContents,
|
||||
|
||||
_MessageBuffer._loadMessagesBatchSize, // load X above
|
||||
_MessageBuffer._loadMessagesBatchSize, // laod X below
|
||||
|
||||
(function(renderedMessages) {
|
||||
requestPayload.renderedMessages = renderedMessages;
|
||||
|
||||
_MessageBuffer.loadMessagesWithJumpPostflight(requestPayload);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
_MessageBuffer.loadMessagesWithJumpPostflight = function(requestPayload) /* PRIVATE */
|
||||
{
|
||||
/* Payload state */
|
||||
var callbackFunction = requestPayload.callbackFunction;
|
||||
var lineNumberContents = requestPayload.lineNumberContents;
|
||||
var lineNumberStandardized = requestPayload.lineNumberStandardized;
|
||||
var renderedMessages = requestPayload.renderedMessages;
|
||||
|
||||
var lineNumbers = null;
|
||||
var html = null;
|
||||
|
||||
/* Perform logging */
|
||||
var renderedMessagesCount = renderedMessages.length;
|
||||
|
||||
console.log("Request to load messages for " + lineNumberContents + " returned " + renderedMessagesCount + " results");
|
||||
|
||||
if (renderedMessagesCount > 0) {
|
||||
/* Array which will house every line number that was loaded.
|
||||
The style needs this information so it can perform whatever action. */
|
||||
lineNumbers = new Array();
|
||||
|
||||
/* Array which will house every segment of HTML to append. */
|
||||
html = new Array();
|
||||
|
||||
/* Process result */
|
||||
for (var i = 0; i < renderedMessagesCount; i++) {
|
||||
var renderedMessage = renderedMessages[i];
|
||||
|
||||
var lineNumber = renderedMessage.lineNumber;
|
||||
|
||||
if (lineNumber) {
|
||||
lineNumbers.push(renderedMessage.lineNumber);
|
||||
}
|
||||
|
||||
html.push(renderedMessage.html);
|
||||
}
|
||||
|
||||
/* When we jump to a line that is not visible, we replace
|
||||
the entire buffer with the rendered messages. This avoids
|
||||
the hassle of having to navigate the DOM merging lines.
|
||||
This may change in the future based on user feedback,
|
||||
but for now this is acceptable. */
|
||||
|
||||
/* Append HTML */
|
||||
var htmlString = html.join("");
|
||||
|
||||
var buffer = MessageBuffer.bufferElement();
|
||||
|
||||
buffer.insertAdjacentHTML('afterbegin', htmlString);
|
||||
|
||||
/* Resize the buffer by removing messages from the bottom
|
||||
so that the only lines that remain are those appended. */
|
||||
_MessageBuffer.resizeBuffer(_MessageBuffer._bufferCurrentSize, false);
|
||||
|
||||
/* Cancel any mutations already queued so that we don't scroll. */
|
||||
/* Place after resizeBuffer() because that triggers a mutation. */
|
||||
buffer.cancelMutation();
|
||||
|
||||
/* Update buffer size to include appended lines. */
|
||||
_MessageBuffer._bufferCurrentSize += lineNumbers.length;
|
||||
|
||||
/* Post line numbers so style can do something with them. */
|
||||
try {
|
||||
_Textual.messageAddedToView(lineNumbers, true);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
/* Toggle automatic scrolling */
|
||||
/* Call after resize so that it has latest state of bottom. */
|
||||
_MessageBuffer.toggleAutomaticScrolling();
|
||||
} // renderedMessagesCount > 0
|
||||
|
||||
/* Try jumping to line and inform callback of result. */
|
||||
callbackFunction(
|
||||
Textual.scrollToElement(lineNumberStandardized)
|
||||
);
|
||||
|
||||
/* Flush state */
|
||||
_MessageBuffer._loadingMessagesDuringJump = false;
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Loading Indicator */
|
||||
/* ************************************************** */
|
||||
|
||||
_MessageBuffer.addLoadingIndicator = function(before, toLine, callbackFunction) /* PRIVATE */
|
||||
{
|
||||
callbackFunction();
|
||||
};
|
||||
|
||||
_MessageBuffer.removeLoadingIndicator = function(fromLine) /* PRIVATE */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Scrolling */
|
||||
/* ************************************************** */
|
||||
|
||||
/* Scrolling */
|
||||
_MessageBuffer._documentScrolledCallback = function(scrolledUpward) /* PRIVATE */
|
||||
{
|
||||
if (scrolledUpward) {
|
||||
if (TextualScroller.isScrolledToTop()) {
|
||||
_MessageBuffer.loadMessagesDuringScroll(true);
|
||||
}
|
||||
|
||||
_MessageBuffer.cancelHardLimitResize();
|
||||
}
|
||||
|
||||
if (scrolledUpward === false && TextualScroller.isScrolledToBottom()) {
|
||||
_MessageBuffer.loadMessagesDuringScroll(false);
|
||||
|
||||
_MessageBuffer.scheduleHardLimitResize();
|
||||
}
|
||||
};
|
||||
|
||||
_MessageBuffer._documentScrolledUpwardCallback = function() /* PRIVATE */
|
||||
{
|
||||
_MessageBuffer._documentScrolledCallback(true);
|
||||
};
|
||||
|
||||
_MessageBuffer._documentScrolledDownwardCallback = function() /* PRIVATE */
|
||||
{
|
||||
_MessageBuffer._documentScrolledCallback(false);
|
||||
};
|
||||
|
||||
_MessageBuffer._automaticScrollingEnabled = true; /* PRIVATE */
|
||||
|
||||
_MessageBuffer.toggleAutomaticScrollingOn = function(turnOn) /* PRIVATE */
|
||||
{
|
||||
if (_MessageBuffer._automaticScrollingEnabled !== turnOn) {
|
||||
_MessageBuffer._automaticScrollingEnabled = turnOn;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (turnOn) {
|
||||
appPrivate.setAutomaticScrollingEnabled(true);
|
||||
} else {
|
||||
appPrivate.setAutomaticScrollingEnabled(false);
|
||||
}
|
||||
};
|
||||
|
||||
_MessageBuffer.toggleAutomaticScrolling = function() /* PRIVATE */
|
||||
{
|
||||
_MessageBuffer.toggleAutomaticScrollingOn(_MessageBuffer._bufferBottomIsComplete);
|
||||
};
|
||||
|
||||
_MessageBuffer.scrolledToBottomOfBuffer = function() /* PRIVATE */
|
||||
{
|
||||
return (_MessageBuffer._bufferBottomIsComplete &&
|
||||
TextualScroller.isScrolledToBottom());
|
||||
};
|
||||
|
||||
MessageBuffer.jumpToLine = function(lineNumber, callbackFunction) /* PUBLIC */
|
||||
{
|
||||
var lineNumberStandardized = lineNumber.standardizedLineNumber();
|
||||
|
||||
if (Textual.scrollToElement(lineNumberStandardized)) {
|
||||
callbackFunction(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_MessageBuffer.loadMessagesWithJump(lineNumberStandardized, callbackFunction);
|
||||
};
|
||||
|
||||
/* Bind to events */
|
||||
document.addEventListener("scrolledUpward", _MessageBuffer._documentScrolledUpwardCallback, false);
|
||||
document.addEventListener("scrolledDownward", _MessageBuffer._documentScrolledDownwardCallback, false);
|
||||
@@ -0,0 +1,107 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
/* Scrolling */
|
||||
Textual.scrollToBottomOfView = function(fireNotification) /* PUBLIC */
|
||||
{
|
||||
TextualScroller.scrollToBottom();
|
||||
|
||||
if (fireNotification) {
|
||||
Textual.viewPositionMovedToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.scrollToTopOfView = function(fireNotification) /* PUBLIC */
|
||||
{
|
||||
TextualScroller.scrollToTop();
|
||||
|
||||
if (fireNotification) {
|
||||
Textual.viewPositionMovedToTop();
|
||||
}
|
||||
};
|
||||
|
||||
Textual.scrollToLine = function(lineNumber) /* PUBLIC */
|
||||
{
|
||||
Textual.jumpToLine(lineNumber);
|
||||
};
|
||||
|
||||
Textual.jumpToLine = function(lineNumber) /* PUBLIC */
|
||||
{
|
||||
MessageBuffer.jumpToLine(
|
||||
lineNumber,
|
||||
|
||||
(function(success) {
|
||||
var scrolledToBottom = false;
|
||||
|
||||
if (success) {
|
||||
scrolledToBottom = TextualScroller.isScrolledToBottom();
|
||||
|
||||
Textual.viewPositionMovedToLine(lineNumber);
|
||||
}
|
||||
|
||||
appPrivate.notifyJumpToLineCallback(lineNumber, success, scrolledToBottom);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
Textual.scrollToElement = function(elementName) /* PUBLIC */
|
||||
{
|
||||
var element = document.getElementById(elementName);
|
||||
|
||||
if (element) {
|
||||
TextualScroller.scrollElementToCenter(element);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Textual.scrollToHistoryIndicator = function() /* PUBLIC */
|
||||
{
|
||||
if (Textual.scrollToElement("mark")) {
|
||||
Textual.viewPositionModToHistoryIndicator();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,580 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
var app = {};
|
||||
var appInternal = {};
|
||||
var appPrivate = {};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Internal */
|
||||
/* ************************************************** */
|
||||
|
||||
appInternal.promiseIndex = 1;
|
||||
appInternal.promisedCallbacks = {};
|
||||
|
||||
appInternal.promiseKept = function(promiseIndex, returnValue)
|
||||
{
|
||||
/* Check to see if an array entry exists for given index. */
|
||||
var callbackFunction = appInternal.promisedCallbacks[promiseIndex];
|
||||
|
||||
/* If an array entry did exist, then perform it as a function. */
|
||||
if (typeof callbackFunction !== "undefined") {
|
||||
callbackFunction(returnValue);
|
||||
|
||||
delete appInternal.promisedCallbacks[promiseIndex];
|
||||
}
|
||||
};
|
||||
|
||||
appInternal.makePromise = function(callbackFunction)
|
||||
{
|
||||
/* Best to be safe about the data we take in. */
|
||||
if (appInternal.isValidCallbackFunction(callbackFunction) === false) {
|
||||
throw "Invalid callback function";
|
||||
}
|
||||
|
||||
/* Insert the promise then return its index (count minus one) */
|
||||
var promiseIndex = appInternal.promiseIndex;
|
||||
|
||||
appInternal.promiseIndex += 1;
|
||||
appInternal.promisedCallbacks[promiseIndex] = callbackFunction;
|
||||
|
||||
return promiseIndex;
|
||||
};
|
||||
|
||||
appInternal.isValidCallbackFunction = function(callbackFunction)
|
||||
{
|
||||
if (callbackFunction && typeof callbackFunction === "function") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Private */
|
||||
/* ************************************************** */
|
||||
|
||||
appPrivate.finishedLayingOutView = function()
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.finishedLayingOutView.postMessage(null);
|
||||
} else {
|
||||
TextualScriptSink.finishedLayingOutView();
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.setAutomaticScrollingEnabled = function(enabled)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
TextualScroller.setAutomaticScrollingEnabled(enabled);
|
||||
} else {
|
||||
TextualScriptSink.setAutomaticScrollingEnabled(enabled);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.setURLAddress = function(object)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.setURLAddress.postMessage(object);
|
||||
} else {
|
||||
TextualScriptSink.setURLAddress(object);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.setSelection = function(object)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.setSelection.postMessage(object);
|
||||
} else {
|
||||
TextualScriptSink.setSelection(object);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.setChannelName = function(object)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.setChannelName.postMessage(object);
|
||||
} else {
|
||||
TextualScriptSink.setChannelName(object);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.setNickname = function(object)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.setNickname.postMessage(object);
|
||||
} else {
|
||||
TextualScriptSink.setNickname(object);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.channelNameDoubleClicked = function()
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.channelNameDoubleClicked.postMessage(null);
|
||||
} else {
|
||||
TextualScriptSink.channelNameDoubleClicked();
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.nicknameDoubleClicked = function()
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.nicknameDoubleClicked.postMessage(null);
|
||||
} else {
|
||||
TextualScriptSink.nicknameDoubleClicked();
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.topicBarDoubleClicked = function()
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.topicBarDoubleClicked.postMessage(null);
|
||||
} else {
|
||||
TextualScriptSink.topicBarDoubleClicked();
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.copySelectionWhenPermitted = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.copySelectionWhenPermitted.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.copySelectionWhenPermitted(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.displayContextMenu = function()
|
||||
{
|
||||
window.webkit.messageHandlers.displayContextMenu.postMessage(null);
|
||||
};
|
||||
|
||||
appPrivate.showInAppPurchaseWindow = function()
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.showInAppPurchaseWindow.postMessage(null);
|
||||
} else {
|
||||
TextualScriptSink.showInAppPurchaseWindow();
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.renderMessagesBefore = function(lineNumber, maximumNumberOfLines, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [lineNumber, maximumNumberOfLines]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.renderMessagesBefore.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.renderMessagesBefore(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.renderMessagesAfter = function(lineNumber, maximumNumberOfLines, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [lineNumber, maximumNumberOfLines]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.renderMessagesAfter.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.renderMessagesAfter(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.renderMessagesInRange = function(lineNumberAfter, lineNumberBefore, maximumNumberOfLines, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [lineNumberAfter, lineNumberBefore, maximumNumberOfLines]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.renderMessagesInRange.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.renderMessagesInRange(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.renderMessageWithSiblings = function(lineNumber, numberOfLinesBefore, numberOfLinesAfter, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [lineNumber, numberOfLinesBefore, numberOfLinesAfter]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.renderMessageWithSiblings.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.renderMessageWithSiblings(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.renderTemplate = function(templateName, templateAttributes, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [templateName, templateAttributes]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.renderTemplate.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.renderTemplate(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.notifyJumpToLineCallback = function(lineNumber, successful, scrolledToBottom)
|
||||
{
|
||||
var dataValue = {"values" : [lineNumber, successful, scrolledToBottom]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.notifyJumpToLineCallback.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.notifyJumpToLineCallback(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.notifyLinesAddedToView = function(lineNumbers)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.notifyLinesAddedToView.postMessage(lineNumbers);
|
||||
} else {
|
||||
TextualScriptSink.notifyLinesAddedToView(lineNumbers);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.notifyLinesRemovedFromView = function(lineNumbers)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.notifyLinesRemovedFromView.postMessage(lineNumbers);
|
||||
} else {
|
||||
TextualScriptSink.notifyLinesRemovedFromView(lineNumbers);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.loadInlineMedia = function(address, uniqueIdentifier, lineNumber, index)
|
||||
{
|
||||
var dataValue = {"values" : [address, uniqueIdentifier, lineNumber, index]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.loadInlineMedia.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.loadInlineMedia(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
appPrivate.encryptionAuthenticateUser = function()
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.encryptionAuthenticateUser.postMessage(null);
|
||||
} else {
|
||||
TextualScriptSink.encryptionAuthenticateUser();
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Public */
|
||||
/* ************************************************** */
|
||||
|
||||
app.isWebKit2 = function()
|
||||
{
|
||||
if (window.webkit && typeof window.webkit.messageHandlers !== "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
app.channelMemberCount = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.channelMemberCount.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.channelMemberCount(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.serverChannelCount = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.serverChannelCount.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.serverChannelCount(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.serverIsConnected = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.serverIsConnected.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.serverIsConnected(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.channelIsJoined = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.channelIsJoined.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.channelIsJoined(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.channelName = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.channelName.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.channelName(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.serverAddress = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.serverAddress.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.serverAddress(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.networkName = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.networkName.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.networkName(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.localUserNickname = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.localUserNickname.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.localUserNickname(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.localUserHostmask = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.localUserHostmask.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.localUserHostmask(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.logToConsole = function(message)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.logToConsole.postMessage(message);
|
||||
} else {
|
||||
TextualScriptSink.logToConsole(message);
|
||||
}
|
||||
};
|
||||
|
||||
app.printDebugInformationToConsole = function(message)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.printDebugInformationToConsole.postMessage(message);
|
||||
} else {
|
||||
TextualScriptSink.printDebugInformationToConsole(message);
|
||||
}
|
||||
};
|
||||
|
||||
app.printDebugInformation = function(message)
|
||||
{
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.printDebugInformation.postMessage(message);
|
||||
} else {
|
||||
TextualScriptSink.printDebugInformation(message);
|
||||
}
|
||||
};
|
||||
|
||||
app.inlineMediaEnabledForView = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.inlineMediaEnabledForView.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.inlineMediaEnabledForView(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.sidebarInversionIsEnabled = function(callbackFunction)
|
||||
{
|
||||
console.warn("app.sidebarInversionIsEnabled() is deprecated. Use app.appearance() instead.");
|
||||
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.sidebarInversionIsEnabled.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.sidebarInversionIsEnabled(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.appearance = function(callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.appearance.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.appearance(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.nicknameColorStyleHash = function(nickname, nicknameColorStyle, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [nickname, nicknameColorStyle]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.nicknameColorStyleHash.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.nicknameColorStyleHash(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.sendPluginPayload = function(payloadLabel, payloadContent)
|
||||
{
|
||||
var dataValue = {"values" : [payloadLabel, payloadContent]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.sendPluginPayload.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.sendPluginPayload(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.styleSettingsRetrieveValue = function(key, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [key]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.styleSettingsRetrieveValue.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.styleSettingsRetrieveValue(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.styleSettingsSetValue = function(key, value, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [key, value]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.styleSettingsSetValue.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.styleSettingsSetValue(dataValue);
|
||||
}
|
||||
};
|
||||
|
||||
app.retrievePreferencesWithMethodName = function(name, callbackFunction)
|
||||
{
|
||||
var promiseIndex = appInternal.makePromise(callbackFunction);
|
||||
|
||||
var dataValue = {"promiseIndex" : promiseIndex, "values" : [name]};
|
||||
|
||||
if (app.isWebKit2()) {
|
||||
window.webkit.messageHandlers.retrievePreferencesWithMethodName.postMessage(dataValue);
|
||||
} else {
|
||||
TextualScriptSink.retrievePreferencesWithMethodName(dataValue);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,227 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
/* ************************************************** */
|
||||
/* Visibility */
|
||||
/* ************************************************** */
|
||||
|
||||
TextualScroller.documentIsVisible = undefined; /* PUBLIC */
|
||||
|
||||
_TextualScroller._documentVisibilityChangedCallback = function() /* PRIVATE */
|
||||
{
|
||||
var documentHidden = document.hidden;
|
||||
|
||||
if (documentHidden) {
|
||||
TextualScroller.documentIsVisible = false;
|
||||
} else {
|
||||
TextualScroller.documentIsVisible = true;
|
||||
|
||||
TextualScroller.restoreScrolledToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
_TextualScroller._documentResizedCallback = function()
|
||||
{
|
||||
TextualScroller.restoreScrolledToBottom();
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Automatic Scroller */
|
||||
/* ************************************************** */
|
||||
|
||||
_TextualScroller._performScrollTimeout = null; /* PRIVATE */
|
||||
_TextualScroller._performScrollNextPass = undefined; /* PRIVATE */
|
||||
|
||||
_TextualScroller.performScrollPreflight = function() /* PRIVATE */
|
||||
{
|
||||
/* Do nothing if we are already planning to scroll. */
|
||||
if (_TextualScroller._performScrollTimeout) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_TextualScroller._performScrollNextPass) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Are we at the bottom? */
|
||||
_TextualScroller._performScrollNextPass =
|
||||
TextualScroller.isScrolledToBottom();
|
||||
};
|
||||
|
||||
_TextualScroller.performScrollCancel = function() /* PRIVATE */
|
||||
{
|
||||
if (_TextualScroller._performScrollTimeout) {
|
||||
clearTimeout(_TextualScroller._performScrollTimeout);
|
||||
|
||||
_TextualScroller._performScrollTimeout = null;
|
||||
}
|
||||
|
||||
_TextualScroller._performScrollNextPass = undefined;
|
||||
};
|
||||
|
||||
TextualScroller.performScroll = function() /* PUBLIC */
|
||||
{
|
||||
/* Do nothing if we are already planning to scroll. */
|
||||
if (_TextualScroller._performScrollTimeout) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do not perform automatic scroll if we weren't at bottom. */
|
||||
if (!_TextualScroller._performScrollNextPass) {
|
||||
return;
|
||||
}
|
||||
|
||||
var performAutomaticScroll = (function() {
|
||||
_TextualScroller._performScrollTimeout = null;
|
||||
_TextualScroller._performScrollNextPass = undefined;
|
||||
|
||||
_TextualScroller.performScroll();
|
||||
});
|
||||
|
||||
_TextualScroller._performScrollTimeout =
|
||||
setTimeout(performAutomaticScroll, 0);
|
||||
};
|
||||
|
||||
_TextualScroller.performScroll = function() /* PRIVATE */
|
||||
{
|
||||
/* Do not perform automatic scroll if is disabled. */
|
||||
if (!TextualScroller.automaticScrollingEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do not perform automatic scroll if the document is not visible. */
|
||||
if (!TextualScroller.documentIsVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Scroll to bottom */
|
||||
TextualScroller.scrollToBottom();
|
||||
};
|
||||
|
||||
/* This function sets a flag that tells the scroller not to do anything,
|
||||
regardless of whether it is visible or not. Visibility will control whether
|
||||
the timer itself is activate, not this function. */
|
||||
TextualScroller.automaticScrollingEnabled = true; /* PRIVATE */
|
||||
|
||||
TextualScroller.setAutomaticScrollingEnabled = function(enabled) /* PUBLIC */
|
||||
{
|
||||
TextualScroller.automaticScrollingEnabled = enabled;
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Mutation Observer Helpers */
|
||||
/* ************************************************** */
|
||||
|
||||
HTMLDocument.prototype.prepareForMutation = function() /* PUBLIC */
|
||||
{
|
||||
_TextualScroller.prepareForMutation();
|
||||
};
|
||||
|
||||
HTMLDocument.prototype.cancelMutation = function() /* PUBLIC */
|
||||
{
|
||||
_TextualScroller.cancelMutation();
|
||||
};
|
||||
|
||||
Element.prototype.prepareForMutation = function() /* PUBLIC */
|
||||
{
|
||||
document.prepareForMutation();
|
||||
};
|
||||
|
||||
Element.prototype.cancelMutation = function() /* PUBLIC */
|
||||
{
|
||||
document.cancelMutation();
|
||||
};
|
||||
|
||||
_TextualScroller.prepareForMutation = function()
|
||||
{
|
||||
_TextualScroller.performScrollPreflight();
|
||||
};
|
||||
|
||||
_TextualScroller.cancelMutation = function()
|
||||
{
|
||||
_TextualScroller.performScrollCancel();
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Mutation Observer */
|
||||
/* ************************************************** */
|
||||
|
||||
_TextualScroller._mutationObserver = null; /* PRIVATE */
|
||||
|
||||
_TextualScroller._mutationObserverCallback = function(mutations) /* PRIVATE */
|
||||
{
|
||||
TextualScroller.performScroll();
|
||||
};
|
||||
|
||||
_TextualScroller.createMutationObserver = function() /* PRIVATE */
|
||||
{
|
||||
var buffer = MessageBuffer.bufferElement();
|
||||
|
||||
var observer = new MutationObserver(_TextualScroller._mutationObserverCallback);
|
||||
|
||||
observer.observe(
|
||||
buffer,
|
||||
|
||||
{
|
||||
childList: true,
|
||||
attributes: true,
|
||||
attributeFilter: ["wants-reveal", "style"], // for inline media
|
||||
subtree: true
|
||||
}
|
||||
);
|
||||
|
||||
_TextualScroller._mutationObserver = observer;
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Events */
|
||||
/* ************************************************** */
|
||||
|
||||
window.addEventListener("resize", _TextualScroller._documentResizedCallback, false);
|
||||
|
||||
document.addEventListener("visibilitychange", _TextualScroller._documentVisibilityChangedCallback, false);
|
||||
|
||||
/* Populate initial visiblity state and maybe create timer */
|
||||
_TextualScroller._documentVisibilityChangedCallback();
|
||||
@@ -0,0 +1,87 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
/* ************************************************** */
|
||||
/* Automatic Scroller */
|
||||
/* ************************************************** */
|
||||
|
||||
TextualScroller.performScroll = function() /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
TextualScroller.setAutomaticScrollingEnabled = function(enabled) /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Mutation Observer */
|
||||
/* ************************************************** */
|
||||
|
||||
HTMLDocument.prototype.prepareForMutation = function() /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
HTMLDocument.prototype.cancelMutation = function() /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
Element.prototype.prepareForMutation = function() /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
Element.prototype.cancelMutation = function() /* PUBLIC */
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
_TextualScroller.createMutationObserver = function() /* PRIVATE */
|
||||
{
|
||||
|
||||
};
|
||||
@@ -0,0 +1,372 @@
|
||||
/* *********************************************************************
|
||||
* _____ _ _
|
||||
* |_ _|____ _| |_ _ _ __ _| |
|
||||
* | |/ _ \ \/ / __| | | |/ _` | |
|
||||
* | | __/> <| |_| |_| | (_| | |
|
||||
* |_|\___/_/\_\\__|\__,_|\__,_|_|
|
||||
*
|
||||
* Copyright (c) 2010 - 2016 Codeux Software, LLC & respective contributors.
|
||||
* Please see Acknowledgements.pdf for additional information.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Textual, "Codeux Software, LLC", nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************** */
|
||||
|
||||
"use strict";
|
||||
|
||||
/* ************************************************** */
|
||||
/* */
|
||||
/* DO NOT OVERRIDE ANYTHING BELOW THIS LINE */
|
||||
/* */
|
||||
/* ************************************************** */
|
||||
|
||||
var TextualScroller = {};
|
||||
var _TextualScroller = {};
|
||||
|
||||
/* ************************************************** */
|
||||
/* State Tracking */
|
||||
/* ************************************************** */
|
||||
|
||||
/* Element to scroll */
|
||||
_TextualScroller._scrolledElement = null;
|
||||
|
||||
/* Minimum distance from bottom to be scrolled upwards
|
||||
before TextualScroller.userScrolled is true. */
|
||||
_TextualScroller._userScrolledMinimum = 25; /* PRIVATE */
|
||||
|
||||
/* Whether or not we are scrolled above the bottom. */
|
||||
TextualScroller.userScrolled = false; /* PUBLIC */
|
||||
|
||||
/* Set to true when scrolled upwards. */
|
||||
TextualScroller.scrolledUpwards = false; /* PUBLIC */
|
||||
|
||||
/* Cached scroll position */
|
||||
TextualScroller.scrollPositionCurrentValue = 0; /* PUBLIC */
|
||||
TextualScroller.scrollPositionPreviousValue = 0; /* PUBLIC */
|
||||
|
||||
/* Cached scroll height */
|
||||
TextualScroller.scrollHeightCurrentValue = 0; /* PUBLIC */
|
||||
TextualScroller.scrollHeightPreviousValue = 0; /* PUBLIC */
|
||||
|
||||
_TextualScroller._documentScrolledCallback = function() /* PRIVATE */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
/* Height of scrollabe area */
|
||||
var scrollHeightPrevious = TextualScroller.scrollHeightCurrentValue;
|
||||
|
||||
var scrollHeightCurrent = scrolledElement.scrollHeight;
|
||||
|
||||
/* The current position scrolled to */
|
||||
var clientHeight = scrolledElement.clientHeight;
|
||||
|
||||
var scrollPositionCurrent = (scrolledElement.scrollTop + clientHeight);
|
||||
|
||||
var scrollPositionPrevious = TextualScroller.scrollPositionCurrentValue;
|
||||
|
||||
/* If nothing changed, we ignore the event.
|
||||
It is possible to receive a scroll event but nothing changes
|
||||
because we ignore elastic scrolling. User can reach bottom,
|
||||
elsastic scroll, then bounce back. We get notification for
|
||||
both times we reach bottom, but values do not change. */
|
||||
if (scrollHeightPrevious === scrollHeightCurrent &&
|
||||
scrollPositionPrevious === scrollPositionCurrent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Even if user is elastic scrolling, we want to record
|
||||
the latest scroll height values. */
|
||||
TextualScroller.scrollHeightPreviousValue = scrollHeightPrevious;
|
||||
TextualScroller.scrollHeightCurrentValue = scrollHeightCurrent;
|
||||
|
||||
/* Ignore elastic scrolling */
|
||||
if (scrollPositionCurrent < clientHeight ||
|
||||
scrollPositionCurrent > scrollHeightCurrent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Only record scroll position changes if we weren't elastic scrolling. */
|
||||
TextualScroller.scrollPositionPreviousValue = scrollPositionPrevious;
|
||||
TextualScroller.scrollPositionCurrentValue = scrollPositionCurrent;
|
||||
|
||||
/* Scrolled upwards? */
|
||||
var scrolledUpwards = (scrollPositionCurrent < scrollPositionPrevious);
|
||||
|
||||
TextualScroller.scrolledUpwards = scrolledUpwards;
|
||||
|
||||
/* User scrolled above bottom? */
|
||||
var userScrolled = ((scrollHeightCurrent - scrollPositionCurrent) > _TextualScroller._userScrolledMinimum);
|
||||
|
||||
TextualScroller.userScrolled = userScrolled;
|
||||
|
||||
/* Post custom scroll event */
|
||||
if (scrolledUpwards) {
|
||||
document.dispatchEvent(new Event('scrolledUpward'));
|
||||
} else {
|
||||
document.dispatchEvent(new Event('scrolledDownward'));
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Position Restore */
|
||||
/* ************************************************** */
|
||||
|
||||
_TextualScroller._restoreScrolledUpwards = undefined; /* PRIVATE */
|
||||
_TextualScroller._restoreScrollHeightFirstValue = undefined; /* PRIVATE */
|
||||
_TextualScroller._restoreScrollHeightSecondValue = undefined; /* PRIVATE */
|
||||
|
||||
TextualScroller.saveRestorationFirstDataPoint = function() /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
_TextualScroller._restoreScrollHeightFirstValue = scrolledElement.scrollHeight;
|
||||
|
||||
_TextualScroller._restoreScrolledUpwards = TextualScroller.scrolledUpwards;
|
||||
};
|
||||
|
||||
TextualScroller.saveRestorationSecondDataPoint = function() /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
_TextualScroller._restoreScrollHeightSecondValue = scrolledElement.scrollHeight;
|
||||
};
|
||||
|
||||
TextualScroller.restoreScrollPosition = function() /* PUBLIC */
|
||||
{
|
||||
var scrollHeightDifference = (_TextualScroller._restoreScrollHeightSecondValue -
|
||||
_TextualScroller._restoreScrollHeightFirstValue);
|
||||
|
||||
if (scrollHeightDifference === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
var scrollTo = 0;
|
||||
|
||||
if (_TextualScroller._restoreScrolledUpwards === false) {
|
||||
scrollTo = (scrolledElement.scrollHeight - scrollHeightDifference);
|
||||
} else {
|
||||
scrollTo = (scrolledElement.scrollHeight + scrollHeightDifference);
|
||||
}
|
||||
|
||||
if (scrollTo < 0) {
|
||||
scrollTo = 0;
|
||||
}
|
||||
|
||||
scrolledElement.scrollTop = scrollTo;
|
||||
|
||||
_TextualScroller._restoreScrollHeightFirstValue = undefined;
|
||||
_TextualScroller._restoreScrollHeightSecondValue = undefined;
|
||||
|
||||
_TextualScroller._restoreScrolledUpwards = undefined;
|
||||
};
|
||||
|
||||
TextualScroller.restoreScrolledToBottom = function() /* PUBLIC */
|
||||
{
|
||||
if (TextualScroller.userScrolled === false) {
|
||||
TextualScroller.scrollToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Element Prototypes */
|
||||
/* ************************************************** */
|
||||
|
||||
Element.prototype.scrollCenterIn = function(parentElement) /* PUBLIC */
|
||||
{
|
||||
if (this === parentElement) {
|
||||
throw "Can't scroll self into center";
|
||||
}
|
||||
|
||||
var parentElementRect = parentElement.getBoundingClientRect();
|
||||
var parentElementHeight = parentElementRect.height;
|
||||
var parentElementTop = parentElement.scrollTop;
|
||||
|
||||
var elementRect = this.getBoundingClientRect();
|
||||
var elementTop = (elementRect.top + parentElementTop);
|
||||
var elementCenter = (elementTop - (parentElementHeight / 2));
|
||||
|
||||
return elementCenter;
|
||||
};
|
||||
|
||||
Element.prototype.percentScrolled = function() /* PUBLIC */
|
||||
{
|
||||
return (((this.scrollTop + this.clientHeight) / this.scrollHeight) * 100.0);
|
||||
};
|
||||
|
||||
Element.prototype.isScrolledToTop = function() /* PUBLIC */
|
||||
{
|
||||
return (this.scrollTop <= 0);
|
||||
};
|
||||
|
||||
Element.prototype.scrollToTop = function() /* PUBLIC */
|
||||
{
|
||||
this.scrollTop = 0;
|
||||
};
|
||||
|
||||
Element.prototype.scrollIntoViewAlignTop = function() /* PUBLIC */
|
||||
{
|
||||
this.scrollIntoView(true);
|
||||
};
|
||||
|
||||
Element.prototype.scrollIntoViewAlignBottom = function() /* PUBLIC */
|
||||
{
|
||||
this.scrollIntoView(false);
|
||||
};
|
||||
|
||||
Element.prototype.isScrolledToBottom = function() /* PUBLIC */
|
||||
{
|
||||
return ((this.scrollTop + this.clientHeight) >= this.scrollHeight);
|
||||
};
|
||||
|
||||
Element.prototype.scrollToBottom = function() /* PUBLIC */
|
||||
{
|
||||
this.scrollTop = this.scrollHeight;
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Element Prototype Proxies */
|
||||
/* ************************************************** */
|
||||
|
||||
TextualScroller.scrollElementToCenter = function(element) /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
var scrollCenter = element.scrollCenterIn(scrolledElement);
|
||||
|
||||
scrolledElement.scrollTop = scrollCenter;
|
||||
};
|
||||
|
||||
TextualScroller.percentScrolled = function() /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
return scrolledElement.percentScrolled();
|
||||
};
|
||||
|
||||
TextualScroller.isScrolledToTop = function() /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
return scrolledElement.isScrolledToTop();
|
||||
};
|
||||
|
||||
TextualScroller.scrollToTop = function() /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
scrolledElement.scrollToTop();
|
||||
};
|
||||
|
||||
TextualScroller.isScrolledToBottom = function() /* PUBLIC */
|
||||
{
|
||||
/* If a timer is set to scroll to the bottom already,
|
||||
then we lie about our current position. */
|
||||
if (_TextualScroller._performScrollTimeout) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!TextualScroller.userScrolled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
return scrolledElement.isScrolledToBottom();
|
||||
};
|
||||
|
||||
TextualScroller.scrollToBottom = function() /* PUBLIC */
|
||||
{
|
||||
var scrolledElement = _TextualScroller._scrolledElement;
|
||||
|
||||
scrolledElement.scrollToBottom();
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
/* Events */
|
||||
/* ************************************************** */
|
||||
|
||||
/* This function is public interface which styles are
|
||||
allowed to override which we should add extra sanity. */
|
||||
TextualScroller.bindToElement = function(newElement) /* PUBLIC */
|
||||
{
|
||||
if (!newElement ||
|
||||
!newElement.nodeType ||
|
||||
newElement.nodeType !== Node.ELEMENT_NODE)
|
||||
{
|
||||
throw "Argument is not an element";
|
||||
}
|
||||
|
||||
var oldElement = _TextualScroller._scrolledElement;
|
||||
|
||||
if (oldElement) {
|
||||
if (oldElement !== document.body) {
|
||||
oldElement.removeEventListener("scroll", _TextualScroller._documentScrolledCallback);
|
||||
} else {
|
||||
window.removeEventListener("scroll", _TextualScroller._documentScrolledCallback);
|
||||
}
|
||||
}
|
||||
|
||||
if (newElement !== document.body) {
|
||||
newElement.addEventListener("scroll", _TextualScroller._documentScrolledCallback, false);
|
||||
} else {
|
||||
window.addEventListener("scroll", _TextualScroller._documentScrolledCallback, false);
|
||||
}
|
||||
|
||||
_TextualScroller._scrolledElement = newElement;
|
||||
};
|
||||
|
||||
_TextualScroller.bindToBestElement = function()
|
||||
{
|
||||
var bindToElement = (function(element) {
|
||||
if (window.getComputedStyle(element).overflowY === "hidden") {
|
||||
return false;
|
||||
}
|
||||
|
||||
TextualScroller.bindToElement(element);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (bindToElement(document.body)) {
|
||||
console.log("Binding to document body");
|
||||
|
||||
return;
|
||||
} else if (bindToElement(Textual.documentBodyElement())) {
|
||||
console.log("Binding to #body_home");
|
||||
|
||||
return;
|
||||
} else if (bindToElement(MessageBuffer.bufferElement())) {
|
||||
console.log("Binding to #message_buffer");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("No element to bind to. Manually call TextualScroller.bindToElement()");
|
||||
};
|
||||
Reference in New Issue
Block a user