/hudson-core/src/main/resources/lib/hudson/progressiveText.jelly

http://github.com/hudson/hudson · Unknown · 94 lines · 85 code · 9 blank · 0 comment · 0 complexity · 8e17f5719b639aba83f1b70d1c50717d MD5 · raw file

  1. <!--
  2. The MIT License
  3. Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo! Inc.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. -->
  20. <!--
  21. Use AJAX to load text data progressively.
  22. This is used to achieve the effect of "tail -f"
  23. without relying on full page reload.
  24. <%@attribute name="href" required="true" description="URL that returns text data" %>
  25. <%@attribute name="idref" required="true" description="ID of the HTML element in which the result is displayed" %>
  26. <%@attribute name="spinner" required="false" description="ID of the HTML element in which the spinner is displayed" %>
  27. <%@attribute name="startOffset" required="false" description="Skip this many bytes rather than showing from start of data" %>
  28. -->
  29. <?jelly escape-by-default='true'?>
  30. <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
  31. <!--
  32. script code
  33. -->
  34. <script>
  35. var scroller = new AutoScroller(document.body);
  36. <j:if test="${requestScope.progressiveTextScript==null}">
  37. <j:set target="${requestScope}" property="progressiveTextScript" value="initialized" />
  38. <!--
  39. fetches the latest update from the server
  40. @param e
  41. DOM node that gets the text appended to
  42. @param href
  43. Where to retrieve additional text from
  44. -->
  45. function fetchNext(e,href) {
  46. var headers = {};
  47. if (e.consoleAnnotator!=undefined)
  48. headers["X-ConsoleAnnotator"] = e.consoleAnnotator;
  49. new Ajax.Request(href,{
  50. method: "post",
  51. parameters: {"start":e.fetchedBytes},
  52. requestHeaders: headers,
  53. onComplete: function(rsp,_) {
  54. <!-- append text and do autoscroll if applicable-->
  55. var stickToBottom = scroller.isSticking();
  56. var text = rsp.responseText;
  57. if(text!="") {
  58. var p = document.createElement("DIV");
  59. e.appendChild(p); // Needs to be first for IE
  60. // Use "outerHTML" for IE; workaround for:
  61. // http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
  62. if (p.outerHTML) {
  63. p.outerHTML = '<pre>'+text+'</pre>';
  64. p = e.lastChild;
  65. }
  66. else p.innerHTML = text;
  67. Behaviour.applySubtree(p);
  68. if(stickToBottom) scroller.scrollToBottom();
  69. }
  70. e.fetchedBytes = rsp.getResponseHeader("X-Text-Size");
  71. e.consoleAnnotator = rsp.getResponseHeader("X-ConsoleAnnotator");
  72. if(rsp.getResponseHeader("X-More-Data")=="true")
  73. setTimeout(function(){fetchNext(e,href);},1000);
  74. <j:if test="${spinner!=null}">
  75. else
  76. $$("${spinner}").style.display = "none";
  77. </j:if>
  78. }
  79. });
  80. }
  81. </j:if>
  82. $$("${idref}").fetchedBytes = ${empty(startOffset)?0:startOffset};
  83. fetchNext($$("${idref}"),"${href}");
  84. </script>
  85. </j:jelly>