/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
- <!--
- The MIT License
- Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo! Inc.
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -->
- <!--
- Use AJAX to load text data progressively.
- This is used to achieve the effect of "tail -f"
- without relying on full page reload.
- <%@attribute name="href" required="true" description="URL that returns text data" %>
- <%@attribute name="idref" required="true" description="ID of the HTML element in which the result is displayed" %>
- <%@attribute name="spinner" required="false" description="ID of the HTML element in which the spinner is displayed" %>
- <%@attribute name="startOffset" required="false" description="Skip this many bytes rather than showing from start of data" %>
- -->
- <?jelly escape-by-default='true'?>
- <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">
- <!--
- script code
- -->
- <script>
- var scroller = new AutoScroller(document.body);
- <j:if test="${requestScope.progressiveTextScript==null}">
- <j:set target="${requestScope}" property="progressiveTextScript" value="initialized" />
- <!--
- fetches the latest update from the server
- @param e
- DOM node that gets the text appended to
- @param href
- Where to retrieve additional text from
- -->
- function fetchNext(e,href) {
- var headers = {};
- if (e.consoleAnnotator!=undefined)
- headers["X-ConsoleAnnotator"] = e.consoleAnnotator;
- new Ajax.Request(href,{
- method: "post",
- parameters: {"start":e.fetchedBytes},
- requestHeaders: headers,
- onComplete: function(rsp,_) {
- <!-- append text and do autoscroll if applicable-->
- var stickToBottom = scroller.isSticking();
- var text = rsp.responseText;
- if(text!="") {
- var p = document.createElement("DIV");
- e.appendChild(p); // Needs to be first for IE
- // Use "outerHTML" for IE; workaround for:
- // http://www.quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
- if (p.outerHTML) {
- p.outerHTML = '<pre>'+text+'</pre>';
- p = e.lastChild;
- }
- else p.innerHTML = text;
- Behaviour.applySubtree(p);
- if(stickToBottom) scroller.scrollToBottom();
- }
- e.fetchedBytes = rsp.getResponseHeader("X-Text-Size");
- e.consoleAnnotator = rsp.getResponseHeader("X-ConsoleAnnotator");
- if(rsp.getResponseHeader("X-More-Data")=="true")
- setTimeout(function(){fetchNext(e,href);},1000);
- <j:if test="${spinner!=null}">
- else
- $$("${spinner}").style.display = "none";
- </j:if>
- }
- });
- }
- </j:if>
- $$("${idref}").fetchedBytes = ${empty(startOffset)?0:startOffset};
- fetchNext($$("${idref}"),"${href}");
- </script>
- </j:jelly>