Plugins/WebKit Message View/Template.html
author <kcochran@trolans.net>
Sat, 19 Oct 2019 17:34:22 -0700
branchfix-autoscroll
changeset 5995 2bfcb17b7076
parent 4647 c8f4e9819f53
permissions -rw-r--r--
Adjust auto-scroll code to use more compatible APIs, adding support for macOS Catalina
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     2
<html>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     3
<head>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     4
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
     5
	<base href="%@">
2531
1b797e2e9b8e Put the 'defer' back for this script. I had thought it was unsupported, but perhaps not.
David Smith <catfish.man@gmail.com>
parents: 2527
diff changeset
     6
	<script type="text/javascript" defer="defer">
1714
73cd8a02f298 Determine the height for marks based off of the body's overallHeight. Fix a bug in the Template where {{{img.scaledToFitImage}}} didn't actually set the width to 100% (the % was being escaped).
Zachary West <zacw@adiumx.com>
parents: 685
diff changeset
     7
		// NOTE:
73cd8a02f298 Determine the height for marks based off of the body's overallHeight. Fix a bug in the Template where {{{img.scaledToFitImage}}} didn't actually set the width to 100% (the % was being escaped).
Zachary West <zacw@adiumx.com>
parents: 685
diff changeset
     8
		// Any percent signs in this file must be escaped!
73cd8a02f298 Determine the height for marks based off of the body's overallHeight. Fix a bug in the Template where {{{img.scaledToFitImage}}} didn't actually set the width to 100% (the % was being escaped).
Zachary West <zacw@adiumx.com>
parents: 685
diff changeset
     9
		// Use two escape signs (%%) to display it, this is passed through a format call!
4646
8fc9e07216a8 We should add content to the WKMV after DOM is ready. Fixes #15377, Message History Only Shows on 1st Tab on Startup.
Adrian Godoroja <robotive@me.com>
parents: 4120
diff changeset
    10
		
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    11
		function appendHTML(html) {
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    12
			var node = document.getElementById("Chat");
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    13
			var range = document.createRange();
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    14
			range.selectNode(node);
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    15
			var documentFragment = range.createContextualFragment(html);
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    16
			node.appendChild(documentFragment);
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
    17
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    18
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    19
		// a coalesced HTML object buffers and outputs DOM objects en masse.
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    20
		// saves A LOT of CSS recalculation time when loading many messages.
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    21
		// (ex. a long twitter timeline)
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    22
		function CoalescedHTML() {
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    23
			var self = this;
2759
81552ae2f111 So, apparently DocumentFragment does just fine with querySelector*. Save some time recalculating that.
Stephen Holt <sholt@adium.im>
parents: 2758
diff changeset
    24
			this.fragment = document.createDocumentFragment();
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    25
			this.timeoutID = 0;
2749
6c65e4eeb0db Only hold the buffer for 10ms. If new content comes in within that 10ms, extend it by another 10ms.
Stephen Holt <sholt@adium.im>
parents: 2748
diff changeset
    26
			this.coalesceRounds = 0;
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    27
			this.isCoalescing = false;
2762
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
    28
			this.isConsecutive = undefined;
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
    29
			this.shouldScroll = undefined;
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    30
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    31
			var appendElement = function (elem) {
2824
38567e9b4371 A few fixes to Template.html and Renkoo message style:
Stephen Holt <sholt@adium.im>
parents: 2809
diff changeset
    32
				document.getElementById("Chat").appendChild(elem);
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    33
			};
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    34
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    35
			function outputHTML() {
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    36
				var insert = document.getElementById("insert");
2765
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
    37
				if(!!insert && self.isConsecutive) {
2764
3627dfff7c3f Insert into the DOM if we're consecutive, append to the end if we're not.
Stephen Holt <sholt@adium.im>
parents: 2763
diff changeset
    38
					insert.parentNode.replaceChild(self.fragment, insert);
3627dfff7c3f Insert into the DOM if we're consecutive, append to the end if we're not.
Stephen Holt <sholt@adium.im>
parents: 2763
diff changeset
    39
				} else {
3627dfff7c3f Insert into the DOM if we're consecutive, append to the end if we're not.
Stephen Holt <sholt@adium.im>
parents: 2763
diff changeset
    40
					if(insert)
3627dfff7c3f Insert into the DOM if we're consecutive, append to the end if we're not.
Stephen Holt <sholt@adium.im>
parents: 2763
diff changeset
    41
						insert.parentNode.removeChild(insert);
3627dfff7c3f Insert into the DOM if we're consecutive, append to the end if we're not.
Stephen Holt <sholt@adium.im>
parents: 2763
diff changeset
    42
					// insert the documentFragment into the live DOM
2824
38567e9b4371 A few fixes to Template.html and Renkoo message style:
Stephen Holt <sholt@adium.im>
parents: 2809
diff changeset
    43
					appendElement(self.fragment);
2764
3627dfff7c3f Insert into the DOM if we're consecutive, append to the end if we're not.
Stephen Holt <sholt@adium.im>
parents: 2763
diff changeset
    44
				}
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    45
				alignChat(self.shouldScroll);
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    46
2753
97a8a57fcef4 We don't neet to create a new root node here.
Stephen Holt <sholt@adium.im>
parents: 2751
diff changeset
    47
				// reset state to empty/non-coalescing
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
    48
				self.shouldScroll = undefined;
2762
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
    49
				self.isConsecutive = undefined;
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    50
				self.isCoalescing = false;
2749
6c65e4eeb0db Only hold the buffer for 10ms. If new content comes in within that 10ms, extend it by another 10ms.
Stephen Holt <sholt@adium.im>
parents: 2748
diff changeset
    51
				self.coalesceRounds = 0;
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    52
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    53
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
    54
			// creates and returns a new documentFragment, containing all content nodes
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
    55
			// which can be inserted as a single node.
2748
eedc8ed773b1 Work on a root HTMLElement, which gives us querySelector() for the whole unattached DOM tree.
Stephen Holt <sholt@adium.im>
parents: 2747
diff changeset
    56
			function createHTMLNode(html) {
2773
eadbff5014e6 Simpler is better, and avoid looping though elements when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2765
diff changeset
    57
				var range = document.createRange();
eadbff5014e6 Simpler is better, and avoid looping though elements when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2765
diff changeset
    58
				range.selectNode(document.getElementById("Chat"));
eadbff5014e6 Simpler is better, and avoid looping though elements when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2765
diff changeset
    59
				return range.createContextualFragment(html);
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
    60
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    61
2756
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
    62
			// removes first insert node from the internal fragment.
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
    63
			function rmInsertNode() {
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
    64
				var insert = self.fragment.querySelector("#insert");
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
    65
				if(insert)
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
    66
					insert.parentNode.removeChild(insert);
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
    67
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    68
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    69
			function setShouldScroll(flag) {
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    70
				if(flag && undefined === self.shouldScroll)
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    71
					self.shouldScroll = flag;
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    72
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    73
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    74
			// hook in a custom method to append new data
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    75
			// to the chat.
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    76
			this.setAppendElementMethod = function (func) {
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    77
				if(typeof func === 'function')
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    78
					appendElement = func;
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
    79
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    80
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
    81
			// (re)start the coalescing timer.
2761
687f12da3240 Increase the coalescing timeout to 25ms, max of 400 coalesced messages (10s of potential lag before display)
Stephen Holt <sholt@adium.im>
parents: 2760
diff changeset
    82
			//   we wait 25ms for a new message to come in.
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
    83
			//   If we get one, restart the timer and wait another 10ms.
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
    84
			//   If not, run outputHTML()
2761
687f12da3240 Increase the coalescing timeout to 25ms, max of 400 coalesced messages (10s of potential lag before display)
Stephen Holt <sholt@adium.im>
parents: 2760
diff changeset
    85
			//  We do this a maximum of 400 times, for 10s max that can be spent
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
    86
			//  coalescing input, since this will block display.
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    87
			this.coalesce = function() {
2749
6c65e4eeb0db Only hold the buffer for 10ms. If new content comes in within that 10ms, extend it by another 10ms.
Stephen Holt <sholt@adium.im>
parents: 2748
diff changeset
    88
				window.clearTimeout(self.timeoutID);
2761
687f12da3240 Increase the coalescing timeout to 25ms, max of 400 coalesced messages (10s of potential lag before display)
Stephen Holt <sholt@adium.im>
parents: 2760
diff changeset
    89
				self.timeoutID = window.setTimeout(outputHTML, 25);
2749
6c65e4eeb0db Only hold the buffer for 10ms. If new content comes in within that 10ms, extend it by another 10ms.
Stephen Holt <sholt@adium.im>
parents: 2748
diff changeset
    90
				self.isCoalescing = true;
2750
5fd4260e1b0d Correct alignment for appending next messages in single user chats.
Stephen Holt <sholt@adium.im>
parents: 2749
diff changeset
    91
				self.coalesceRounds += 1;
2761
687f12da3240 Increase the coalescing timeout to 25ms, max of 400 coalesced messages (10s of potential lag before display)
Stephen Holt <sholt@adium.im>
parents: 2760
diff changeset
    92
				if(400 < self.coalesceRounds)
2749
6c65e4eeb0db Only hold the buffer for 10ms. If new content comes in within that 10ms, extend it by another 10ms.
Stephen Holt <sholt@adium.im>
parents: 2748
diff changeset
    93
					self.cancel();
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    94
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
    95
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    96
			// if we need to append content into an insertion div,
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    97
			// we need to clear the buffer and cancel the timeout.
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    98
			this.cancel = function() {
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
    99
				if(self.isCoalescing) {
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   100
					window.clearTimeout(self.timeoutID);
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   101
					outputHTML();
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   102
				}
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   103
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   104
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   105
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
   106
			// coalased analogs to the global functions
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   107
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   108
			this.append = function(html, shouldScroll) {
2762
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
   109
				// if we started this fragment with a consecuative message,
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
   110
				// cancel and output before we continue
2765
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
   111
				if(self.isConsecutive) {
2762
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
   112
					self.cancel();
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
   113
				}
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
   114
				self.isConsecutive = false;
2756
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
   115
				rmInsertNode();
2750
5fd4260e1b0d Correct alignment for appending next messages in single user chats.
Stephen Holt <sholt@adium.im>
parents: 2749
diff changeset
   116
				var node = createHTMLNode(html);
5fd4260e1b0d Correct alignment for appending next messages in single user chats.
Stephen Holt <sholt@adium.im>
parents: 2749
diff changeset
   117
				self.fragment.appendChild(node);
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   118
2758
1baad7856ddd Set temporary objects to null after we're not using them.
Stephen Holt <sholt@adium.im>
parents: 2757
diff changeset
   119
				node = null;
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   120
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
   121
				setShouldScroll(shouldScroll);
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   122
				self.coalesce();
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   123
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   124
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   125
			this.appendNext = function(html, shouldScroll) {
2765
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
   126
				if(undefined === self.isConsecutive)
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
   127
					self.isConsecutive = true;
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
   128
				var node = createHTMLNode(html);
2750
5fd4260e1b0d Correct alignment for appending next messages in single user chats.
Stephen Holt <sholt@adium.im>
parents: 2749
diff changeset
   129
				var insert = self.fragment.querySelector("#insert");
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   130
				if(insert) {
2751
70e57c04f788 Don't assume a single root node.
Stephen Holt <sholt@adium.im>
parents: 2750
diff changeset
   131
					insert.parentNode.replaceChild(node, insert);
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   132
				} else {
2765
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
   133
					self.fragment.appendChild(node);
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   134
				}
2765
80187ccccb36 don't call CoalescedHTML.prototype.append() from CoalescedHTML.prototype.appendNext(). That's bad juju.
Stephen Holt <sholt@adium.im>
parents: 2764
diff changeset
   135
				node = null;
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
   136
				setShouldScroll(shouldScroll);
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   137
				self.coalesce();
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   138
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   139
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   140
			this.replaceLast = function (html, shouldScroll) {
2756
0c12378de034 Reduce some duplicate code here.
Stephen Holt <sholt@adium.im>
parents: 2754
diff changeset
   141
				rmInsertNode();
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   142
				var node = createHTMLNode(html);
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   143
				var lastMessage = self.fragment.lastChild;
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   144
				lastMessage.parentNode.replaceChild(node, lastMessage);
2758
1baad7856ddd Set temporary objects to null after we're not using them.
Stephen Holt <sholt@adium.im>
parents: 2757
diff changeset
   145
				node = null;
2841
b0e9a4466823 Only set shouldScroll property on the first new message. Prevents a long cascade of new messages from busting the scroll position before calling nearBottom().
Stephen Holt <sholt@adium.im>
parents: 2824
diff changeset
   146
				setShouldScroll(shouldScroll);
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   147
			}
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   148
		}
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   149
		var coalescedHTML;
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   150
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   151
		//Appending new content to the message view
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   152
		function appendMessage(html) {
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   153
			var shouldScroll;
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   154
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   155
			// Only call nearBottom() if should scroll is undefined.
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   156
			if(undefined === coalescedHTML.shouldScroll) {
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   157
				shouldScroll = nearBottom();
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   158
			} else {
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   159
				shouldScroll = coalescedHTML.shouldScroll;
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   160
			}
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   161
			appendMessageNoScroll(html, shouldScroll);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   162
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   163
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   164
		function appendMessageNoScroll(html, shouldScroll) {
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   165
			shouldScroll = shouldScroll || false;
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
   166
			// always try to coalesce new, non-griuped, messages
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   167
			coalescedHTML.append(html, shouldScroll)
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   168
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   169
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   170
		function appendNextMessage(html){
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   171
			var shouldScroll;
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   172
			if(undefined === coalescedHTML.shouldScroll) {
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   173
				shouldScroll = nearBottom();
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   174
			} else {
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   175
				shouldScroll = coalescedHTML.shouldScroll;
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   176
			}
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   177
			appendNextMessageNoScroll(html, shouldScroll);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   178
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   179
2746
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   180
		function appendNextMessageNoScroll(html, shouldScroll){
38433bea7f5e If we're already coalessing messages, fold in the last message and coalesce that one too.
Stephen Holt <sholt@adium.im>
parents: 2745
diff changeset
   181
			shouldScroll = shouldScroll || false;
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
   182
			// only group next messages if we're already coalescing input
2762
9642be635e28 If we start a consecuative message outside an existing coalescing round, start a new one that's cancelled once we get a message from a new sender.
Stephen Holt <sholt@adium.im>
parents: 2761
diff changeset
   183
			coalescedHTML.appendNext(html, shouldScroll);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   184
		}
2514
7d7e889ad3af Patch from mathuaerknedam. Fixes ticket #9689.
David Smith <catfish.man@gmail.com>
parents: 1714
diff changeset
   185
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   186
		function replaceLastMessage(html){
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   187
			var shouldScroll;
2757
ea5902712400 Comments are nice. I like comments.
Stephen Holt <sholt@adium.im>
parents: 2756
diff changeset
   188
			// only replace messages if we're already coalescing
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   189
			if(coalescedHTML.isCoalescing){
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   190
				if(undefined === coalescedHTML.shouldScroll) {
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   191
					shouldScroll = nearBottom();
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   192
				} else {
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   193
					shouldScroll = coalescedHTML.shouldScroll;
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   194
				}
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   195
				coalescedHTML.replaceLast(html, shouldScroll);
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   196
			} else {
2760
15f5873def89 Try not to call nearBottom() when we don't have to.
Stephen Holt <sholt@adium.im>
parents: 2759
diff changeset
   197
				shouldScroll = nearBottom();
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   198
				//Retrieve the current insertion point, then remove it
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   199
				//This requires that there have been an insertion point... is there a better way to retrieve the last element? -evands
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   200
				var insert = document.getElementById("insert");
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   201
				if(insert){
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   202
					var parentNode = insert.parentNode;
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   203
					parentNode.removeChild(insert);
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   204
					var lastMessage = document.getElementById("Chat").lastChild;
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   205
					document.getElementById("Chat").removeChild(lastMessage);
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   206
				}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   207
2754
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   208
				//Now append the message itself
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   209
				appendHTML(html);
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   210
b4cc4b3566d3 Add replaceLast support to already coalesced message streams.
Stephen Holt <sholt@adium.im>
parents: 2753
diff changeset
   211
				alignChat(shouldScroll);
523
be67d382603f If a style doesn't include an 'insert' div but does let the default template.html be used by not overriding it, we now fall back on not treating the addition as a consecutive addition. This fixes a small number of cases of old styles which don't have an 'insert' div in their Status.html, but does not fix most of them since most override the template.html, as well. Refs #10921
Evan Schoenberg
parents: 0
diff changeset
   212
			}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   213
		}
2514
7d7e889ad3af Patch from mathuaerknedam. Fixes ticket #9689.
David Smith <catfish.man@gmail.com>
parents: 1714
diff changeset
   214
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   215
		//Auto-scroll to bottom.  Use nearBottom to determine if a scrollToBottom is desired.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   216
		function nearBottom() {
5995
2bfcb17b7076 Adjust auto-scroll code to use more compatible APIs, adding support for macOS Catalina
<kcochran@trolans.net>
parents: 4647
diff changeset
   217
			return ( window.scrollY >= ( document.body.offsetHeight - ( window.innerHeight * 1.2 ) ) );
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   218
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   219
		function scrollToBottom() {
5995
2bfcb17b7076 Adjust auto-scroll code to use more compatible APIs, adding support for macOS Catalina
<kcochran@trolans.net>
parents: 4647
diff changeset
   220
			window.scrollTo(0, document.body.scrollHeight);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   221
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   222
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   223
		//Dynamically exchange the active stylesheet
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   224
		function setStylesheet( id, url ) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   225
			var code = "<style id=\"" + id + "\" type=\"text/css\" media=\"screen,print\">";
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   226
			if( url.length )
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   227
				code += "@import url( \"" + url + "\" );";
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   228
			code += "</style>";
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   229
			var range = document.createRange();
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   230
			var head = document.getElementsByTagName( "head" ).item(0);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   231
			range.selectNode( head );
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   232
			var documentFragment = range.createContextualFragment( code );
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   233
			head.removeChild( document.getElementById( id ) );
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   234
			head.appendChild( documentFragment );
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   235
		}
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   236
2527
26d53e9f30c5 A few more simplifications, getting Template.html down to an even 200 lines
David Smith <catfish.man@gmail.com>
parents: 2525
diff changeset
   237
		/* Converts emoticon images to textual emoticons; all emoticons in message if alt is held */
26d53e9f30c5 A few more simplifications, getting Template.html down to an even 200 lines
David Smith <catfish.man@gmail.com>
parents: 2525
diff changeset
   238
		document.onclick = function imageCheck() {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   239
			var node = event.target;
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   240
			if (node.tagName.toLowerCase() != 'img')
2518
7a58335a87f8 Patch from MartialL that fixes #3807. A few relatively minor changes by me
David Smith <catfish.man@gmail.com>
parents: 2517
diff changeset
   241
				return;
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   242
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   243
			imageSwap(node, false);
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   244
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   245
2527
26d53e9f30c5 A few more simplifications, getting Template.html down to an even 200 lines
David Smith <catfish.man@gmail.com>
parents: 2525
diff changeset
   246
		/* Converts textual emoticons to images if textToImagesFlag is true, otherwise vice versa */
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   247
		function imageSwap(node, textToImagesFlag) {
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   248
			var shouldScroll = nearBottom();
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   249
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   250
			var images = [node];
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   251
			if (event.altKey) {
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   252
				while (node.id != "Chat" && node.parentNode.id != "Chat")
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   253
					node = node.parentNode;
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   254
				images = node.querySelectorAll(textToImagesFlag ? "a" : "img");
2517
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   255
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   256
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   257
			for (var i = 0; i < images.length; i++) {
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   258
				textToImagesFlag ? textToImage(images[i]) : imageToText(images[i]);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   259
			}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   260
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   261
			alignChat(shouldScroll);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   262
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   263
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   264
		function textToImage(node) {
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   265
			if (!node.getAttribute("isEmoticon"))
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   266
				return;
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   267
			//Swap the image/text
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   268
			var img = document.createElement('img');
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   269
			img.setAttribute('src', node.getAttribute('src'));
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   270
			img.setAttribute('alt', node.firstChild.nodeValue);
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   271
			img.className = node.className;
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   272
			node.parentNode.replaceChild(img, node);
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   273
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   274
2517
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   275
		function imageToText(node)
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   276
		{
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   277
			if (client.zoomImage(node) || !node.alt)
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   278
				return;
2517
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   279
			var a = document.createElement('a');
2525
a4caa7c2401d Simplify Template.html a bunch. I think this may also fix a few emoticon issues
David Smith <catfish.man@gmail.com>
parents: 2518
diff changeset
   280
			a.setAttribute('onclick', 'imageSwap(this, true)');
2517
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   281
			a.setAttribute('src', node.getAttribute('src'));
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   282
			a.setAttribute('isEmoticon', true);
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   283
			a.className = node.className;
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   284
			var text = document.createTextNode(node.alt);
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   285
			a.appendChild(text);
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   286
			node.parentNode.replaceChild(a, node);
83ef5f5390a3 Patch from MartialL that fixes #3807
David Smith <catfish.man@gmail.com>
parents: 2514
diff changeset
   287
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   288
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   289
		//Align our chat to the bottom of the window.  If true is passed, view will also be scrolled down
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   290
		function alignChat(shouldScroll) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   291
			var windowHeight = window.innerHeight;
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   292
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   293
			if (windowHeight > 0) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   294
				var contentElement = document.getElementById('Chat');
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   295
				var heightDifference = (windowHeight - contentElement.offsetHeight);
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   296
				if (heightDifference > 0) {
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   297
					contentElement.style.position = 'relative';
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   298
					contentElement.style.top = heightDifference + 'px';
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   299
				} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   300
					contentElement.style.position = 'static';
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   301
				}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   302
			}
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   303
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   304
			if (shouldScroll) scrollToBottom();
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   305
		}
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   306
2527
26d53e9f30c5 A few more simplifications, getting Template.html down to an even 200 lines
David Smith <catfish.man@gmail.com>
parents: 2525
diff changeset
   307
		window.onresize = function windowDidResize(){
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   308
			alignChat(true/*nearBottom()*/); //nearBottom buggy with inactive tabs
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   309
		}
4120
34999f4a034b Tweak the Alignchat function so remove a (potential) recalc and make it slightly easier to read.
mathuaerknedam
parents: 3252
diff changeset
   310
2824
38567e9b4371 A few fixes to Template.html and Renkoo message style:
Stephen Holt <sholt@adium.im>
parents: 2809
diff changeset
   311
		function initStyle() {
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   312
			alignChat(true);
2824
38567e9b4371 A few fixes to Template.html and Renkoo message style:
Stephen Holt <sholt@adium.im>
parents: 2809
diff changeset
   313
			if(!coalescedHTML)
38567e9b4371 A few fixes to Template.html and Renkoo message style:
Stephen Holt <sholt@adium.im>
parents: 2809
diff changeset
   314
				coalescedHTML = new CoalescedHTML();
2738
58dcead8d4c0 Coalesce DOM manipulations into a single DOM insertion every 200ms.
Stephen Holt <sholt@adium.im>
parents: 2531
diff changeset
   315
		}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   316
	</script>
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   317
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   318
	<style type="text/css">
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   319
		.actionMessageUserName { display:none; }
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   320
		.actionMessageBody:before { content:"*"; }
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   321
		.actionMessageBody:after { content:"*"; }
3252
b6246b272433 Add 'text-rendering: optimizelegibility;' to the default message style css. Without it, text rendering is supposedly optimized for speed, but it actually makes Adium slightly SLOWER (1 sec/ 1000 msgs in stresstest msginout). Perhaps the only noticeable effect is that this enables ligatures and kerning in fonts that support it, but it's sure to be appreciated by the typographically sensitive. :)
mathuaerknedam
parents: 2852
diff changeset
   322
		* { word-wrap:break-word; text-rendering: optimizelegibility; }
2809
db7418b3e2f9 Set the max width to 100%, don't scale all images up to 100%.
Zachary West <zacw@adium.im>
parents: 2773
diff changeset
   323
		img.scaledToFitImage { height: auto; max-width: 100%%; }
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   324
	</style>
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   325
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   326
	<!-- This style is shared by all variants. !-->
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   327
	<style id="baseStyle" type="text/css" media="screen,print">
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   328
		%@
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   329
	</style>
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   330
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   331
	<!-- Although we call this mainStyle for legacy reasons, it's actually the variant style !-->
685
0f4a11302be7 Patch from mathuaerknedam that fixes #11602
David Smith
parents: 523
diff changeset
   332
	<style id="mainStyle" type="text/css" media="screen,print">
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   333
		@import url( "%@" );
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   334
	</style>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   335
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   336
</head>
2824
38567e9b4371 A few fixes to Template.html and Renkoo message style:
Stephen Holt <sholt@adium.im>
parents: 2809
diff changeset
   337
<body onload="initStyle();" style="==bodyBackground==">
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   338
%@
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   339
<div id="Chat">
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   340
</div>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   341
%@
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   342
</body>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   343
</html>