PageRenderTime 35ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/emesene/gui/base/template.html

https://github.com/esmanhotto/emesene
HTML | 366 lines | 292 code | 74 blank | 0 comment | 0 complexity | babe37a20d5fcd84a3863a85998c0739 MD5 | raw file
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <base href="%@">
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. isDebug = false;
  10. // Fade interval in milliseconds
  11. // Make this larger if you experience performance issues
  12. Fadomatic.INTERVAL_MILLIS = 50;
  13. // Creates a fader
  14. // element - The element to fade
  15. // speed - The speed to fade at, from 0.0 to 100.0
  16. // initialOpacity (optional, default 100) - element's starting opacity, 0 to 100
  17. // minOpacity (optional, default 0) - element's minimum opacity, 0 to 100
  18. // maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100
  19. function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) {
  20. this._element = element;
  21. this._intervalId = null;
  22. this._rate = rate;
  23. this._isFadeOut = true;
  24. // Set initial opacity and bounds
  25. // NB use 99 instead of 100 to avoid flicker at start of fade
  26. this._minOpacity = 0;
  27. this._maxOpacity = 99;
  28. this._opacity = 99;
  29. if (typeof minOpacity != 'undefined') {
  30. if (minOpacity < 0) {
  31. this._minOpacity = 0;
  32. } else if (minOpacity > 99) {
  33. this._minOpacity = 99;
  34. } else {
  35. this._minOpacity = minOpacity;
  36. }
  37. }
  38. if (typeof maxOpacity != 'undefined') {
  39. if (maxOpacity < 0) {
  40. this._maxOpacity = 0;
  41. } else if (maxOpacity > 99) {
  42. this._maxOpacity = 99;
  43. } else {
  44. this._maxOpacity = maxOpacity;
  45. }
  46. if (this._maxOpacity < this._minOpacity) {
  47. this._maxOpacity = this._minOpacity;
  48. }
  49. }
  50. if (typeof initialOpacity != 'undefined') {
  51. if (initialOpacity > this._maxOpacity) {
  52. this._opacity = this._maxOpacity;
  53. } else if (initialOpacity < this._minOpacity) {
  54. this._opacity = this._minOpacity;
  55. } else {
  56. this._opacity = initialOpacity;
  57. }
  58. }
  59. // See if we're using W3C opacity, MSIE filter, or just
  60. // toggling visiblity
  61. if(typeof element.style.opacity != 'undefined') {
  62. this._updateOpacity = this._updateOpacityW3c;
  63. } else if(typeof element.style.filter != 'undefined') {
  64. // If there's not an alpha filter on the element already,
  65. // add one
  66. if (element.style.filter.indexOf("alpha") == -1) {
  67. // Attempt to preserve existing filters
  68. var existingFilters="";
  69. if (element.style.filter) {
  70. existingFilters = element.style.filter+" ";
  71. }
  72. element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
  73. }
  74. this._updateOpacity = this._updateOpacityMSIE;
  75. } else {
  76. this._updateOpacity = this._updateVisibility;
  77. }
  78. this._updateOpacity();
  79. }
  80. // Initiates a fade out
  81. Fadomatic.prototype.fadeOut = function () {
  82. this._isFadeOut = true;
  83. this._beginFade();
  84. }
  85. // Initiates a fade in
  86. Fadomatic.prototype.fadeIn = function () {
  87. this._isFadeOut = false;
  88. this._beginFade();
  89. }
  90. // Makes the element completely opaque, stops any fade in progress
  91. Fadomatic.prototype.show = function () {
  92. this.haltFade();
  93. this._opacity = this._maxOpacity;
  94. this._updateOpacity();
  95. }
  96. // Makes the element completely transparent, stops any fade in progress
  97. Fadomatic.prototype.hide = function () {
  98. this.haltFade();
  99. this._opacity = 0;
  100. this._updateOpacity();
  101. }
  102. // Halts any fade in progress
  103. Fadomatic.prototype.haltFade = function () {
  104. clearInterval(this._intervalId);
  105. }
  106. // Resumes a fade where it was halted
  107. Fadomatic.prototype.resumeFade = function () {
  108. this._beginFade();
  109. }
  110. // Pseudo-private members
  111. Fadomatic.prototype._beginFade = function () {
  112. this.haltFade();
  113. var objref = this;
  114. this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS);
  115. }
  116. Fadomatic.prototype._tickFade = function () {
  117. if (this._isFadeOut) {
  118. this._opacity -= this._rate;
  119. if (this._opacity < this._minOpacity) {
  120. this._opacity = this._minOpacity;
  121. this.haltFade();
  122. }
  123. } else {
  124. this._opacity += this._rate;
  125. if (this._opacity > this._maxOpacity ) {
  126. this._opacity = this._maxOpacity;
  127. this.haltFade();
  128. }
  129. }
  130. this._updateOpacity();
  131. }
  132. Fadomatic.prototype._updateVisibility = function () {
  133. if (this._opacity > 0) {
  134. this._element.style.visibility = 'visible';
  135. } else {
  136. this._element.style.visibility = 'hidden';
  137. }
  138. }
  139. Fadomatic.prototype._updateOpacityW3c = function () {
  140. this._element.style.opacity = this._opacity/100;
  141. this._updateVisibility();
  142. }
  143. Fadomatic.prototype._updateOpacityMSIE = function () {
  144. this._element.filters.alpha.opacity = this._opacity;
  145. this._updateVisibility();
  146. }
  147. Fadomatic.prototype._updateOpacity = null;
  148. //Do this on load
  149. function initEvents() {
  150. if(document.getElementById("heading") == null){
  151. document.getElementById("bodyNode").style.marginTop = "5px";
  152. }
  153. if(isDebug == false) {
  154. document.getElementById("debug").style.display = "none";
  155. }
  156. alignChat(true);
  157. }
  158. //Debugging function
  159. function trace(msg) {
  160. var node = document.createElement("div");
  161. var debugCon = document.getElementById("debug");
  162. node.innerHTML = msg;
  163. debugCon.appendChild(node);
  164. }
  165. //Appending new content to the message view
  166. function appendMessage(html) {
  167. var shouldScroll = nearBottom();
  168. //Remove any existing insertion point
  169. var insert = document.getElementById("insert");
  170. if(insert) insert.parentNode.removeChild(insert);
  171. //Append the new message to the bottom of our chat block
  172. var chat = document.getElementById("Chat");
  173. var range = document.createRange();
  174. range.selectNode(chat);
  175. var documentFragment = range.createContextualFragment(html);
  176. var myFrag = chat.appendChild(documentFragment);
  177. //var frag = insert.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  178. try {
  179. var fader = new Fadomatic(myFrag, 9, 0, 0, 95);
  180. fader.fadeIn();
  181. } catch(e) {
  182. trace(e);
  183. }
  184. alignChat(true);
  185. }
  186. function appendNextMessage(html){
  187. var shouldScroll = nearBottom();
  188. //Locate the insertion point
  189. var insert = document.getElementById("insert");
  190. //make new node
  191. range = document.createRange();
  192. range.selectNode(insert.parentNode);
  193. newNode = range.createContextualFragment(html);
  194. //swap
  195. var pointer = insert.parentNode;
  196. insert.parentNode.replaceChild(newNode,insert);
  197. var els = pointer.getElementsByTagName("div");
  198. alignChat(true);
  199. }
  200. //Auto-scroll to bottom. Use nearBottom to determine if a scrollToBottom is desired.
  201. function nearBottom() {
  202. return ( document.body.scrollTop >= ( document.body.offsetHeight - ( window.innerHeight * 1.2 ) ) );
  203. }
  204. var intervall_scroll;
  205. function scrollToBottom() {
  206. //document.body.scrollTop = (document.body.scrollHeight-window.innerHeight);
  207. //return;
  208. if( intervall_scroll ) clearInterval( intervall_scroll );
  209. intervall_scroll = setInterval( function() {
  210. var target_scroll = (document.body.scrollHeight-window.innerHeight);
  211. var scrolldiff = target_scroll - document.body.scrollTop;
  212. if ( document.body.scrollTop != target_scroll ) {
  213. var saved_scroll = document.body.scrollTop;
  214. document.body.scrollTop += scrolldiff / 5 + ( scrolldiff >= 0 ? (scrolldiff != 0 ) : -1 );
  215. } else {
  216. saved_scroll = -1;
  217. clearInterval( intervall_scroll );
  218. }
  219. } , 10 );
  220. return;
  221. }
  222. //Dynamically exchange the active stylesheet
  223. function setStylesheet( id, url ) {
  224. var code = "<style id=\"" + id + "\" type=\"text/css\" media=\"screen,print\">";
  225. if( url.length ) code += "@import url( \"" + url + "\" );";
  226. code += "</style>";
  227. var range = document.createRange();
  228. var head = document.getElementsByTagName( "head" ).item(0);
  229. range.selectNode( head );
  230. documentFragment = range.createContextualFragment( code );
  231. head.removeChild( document.getElementById( id ) );
  232. head.appendChild( documentFragment );
  233. }
  234. //Swap an image with its alt-tag text on click
  235. document.onclick = imageCheck;
  236. function imageCheck() {
  237. node = event.target;
  238. if(node.tagName == 'IMG' && node.alt && node.className!="avatar") {
  239. a = document.createElement('a');
  240. a.setAttribute('onclick', 'imageSwap(this)');
  241. a['src'] = node.src;
  242. a['alt'] = node.alt;
  243. a['name'] = node.name;
  244. a.className = node.className;
  245. text = document.createTextNode(node.alt);
  246. a.appendChild(text);
  247. node.parentNode.replaceChild(a, node);
  248. }
  249. }
  250. function imageSwap(node) {
  251. shouldScroll = nearBottom();
  252. //Swap the image/text
  253. img = document.createElement('img');
  254. img['src'] = node.src;
  255. img['alt'] = node.alt;
  256. img['name'] = node.name;
  257. img.className = node.className;
  258. node.parentNode.replaceChild(img, node);
  259. alignChat(shouldScroll);
  260. }
  261. //Align our chat to the bottom of the window. If true is passed, view will also be scrolled down
  262. function alignChat(shouldScroll) {
  263. var windowHeight = window.innerHeight;
  264. if(windowHeight > 0) {
  265. var contentElement = document.getElementById('Chat');
  266. var contentHeight = contentElement.offsetHeight;
  267. if (windowHeight - contentHeight > 0) {
  268. contentElement.style.position = 'relative';
  269. contentElement.style.top = '0px';
  270. } else {
  271. contentElement.style.position = 'static';
  272. }
  273. }
  274. if(shouldScroll) scrollToBottom();
  275. }
  276. function windowDidResize() {
  277. alignChat(true/*nearBottom()*/); //nearBottom buggy with inavtive tabs
  278. }
  279. window.onresize = windowDidResize;
  280. //]]>
  281. </script>
  282. <style id="mainStyle" type="text/css" media="screen,print"> @import url( "%@" ); </style>
  283. %@
  284. </head>
  285. <body id="bodyNode" onload="initEvents()">
  286. %@
  287. <div id="Chat">
  288. </div>
  289. %@
  290. <div id="debug"></div>
  291. </body>
  292. </html>