PageRenderTime 34ms CodeModel.GetById 28ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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