if (Function.prototype.bind == null) { Function.prototype.bind = function(object) { var __method = this; return function() { return __method.apply(object, arguments); } } } if (typeof(Wicket) == "undefined") Wicket = { }; Wicket.$ = function(arg) { if (arg == null || typeof(arg) == "undefined") { return null; } if (arguments.length > 1) { var e=[]; for (var i=0; i 50 || Wicket.Browser.isKHTML() || Wicket.Browser.isSafari()) { this.depth = 0; window.setTimeout(run, 1); } else { this.depth ++; run(); } } }, start: function() { this.processNext(); }, notify: function() { this.processNext(); } } Wicket.replaceOuterHtmlIE = function(element, text) { var marker = "__WICKET_JS_REMOVE_X9F4A__"; function markIframe(text) { var t = text; var r = /<\s*iframe/i; while ((m = t.match(r)) != null) { t = Wicket.replaceAll(t, m[0], "<" + marker + m[0].substring(1)); } return t; } function removeIframeMark(text) { return Wicket.replaceAll(text, marker, ""); } if (element.tagName == "SCRIPT") { var tempDiv = document.createElement("div"); tempDiv.innerHTML = "" + text + "
"; var script = tempDiv.childNodes[0].childNodes[0].innerHTML; element.outerHtml = text; try { eval(script); } catch (e) { Wicket.Log.error("Wicket.replaceOuterHtmlIE: " + e + ": eval -> " + script); } return; } var parent = element.parentNode; var tn = element.tagName; var tempDiv = document.createElement("div"); var tempParent; var scripts = new Array(); if (window.parent == window || window.parent == null) { document.body.appendChild(tempDiv); } if (tn != 'TBODY' && tn != 'TR' && tn != "TD" && tn != "THEAD" && tn != "TFOOT" && tn != "TH") { tempDiv.innerHTML = '' + markIframe(text) + '
'; var s = tempDiv.getElementsByTagName("script"); for (var i = 0; i < s.length; ++i) { scripts.push(s[i]); } tempDiv.innerHTML = '
' + text + '
'; tempParent = tempDiv.childNodes[0]; tempParent.parentNode.removeChild(tempParent); } else { tempDiv.innerHTML = '
' + markIframe(text) + '
'; var s = tempDiv.getElementsByTagName("script"); for (var i = 0; i < s.length; ++i) { scripts.push(s[i]); } tempDiv.innerHTML = '' + text + '
'; tempParent = tempDiv.getElementsByTagName(tn).item(0).parentNode; } while(tempParent.childNodes.length > 0) { var tempElement = tempParent.childNodes[0]; parent.insertBefore(tempElement, element); tempElement = null; } if(element.style.backgroundImage) element.style.backgroundImage = ""; parent.removeChild(element); element.outerHTML = ""; element = ""; if (window.parent == window || window.parent == null) { if(tempDiv.style.backgroundImage) tempDiv.style.backgroundImage = ""; document.body.removeChild(tempDiv); } tempDiv.outerHTML = ""; parent = null; tempDiv = null; tempParent = null; for (i = 0; i < scripts.length; ++i) { Wicket.Head.addJavascripts(scripts[i], removeIframeMark); } } Wicket.replaceOuterHtmlSafari = function(element, text) { if (element.tagName == "SCRIPT") { var tempDiv = document.createElement("div"); tempDiv.innerHTML = text; var script = tempDiv.childNodes[0].innerHTML; if (typeof(script) != "string") { script = tempDiv.childNodes[0].text; } element.outerHTML = text; try { eval(script); } catch (e) { Wicket.Log.error("Wicket.replaceOuterHtmlSafari: " + e + ": eval -> " + script); } return; } var parent = element.parentNode; var next = element.nextSibling; var index = 0; while (parent.childNodes[index] != element) { ++index; } element.outerHTML = text; element = parent.childNodes[index]; while (element != next) { try { Wicket.Head.addJavascripts(element); } catch (ignore) { } element = element.nextSibling; } } Wicket.replaceOuterHtml = function(element, text) { if (Wicket.Browser.isIE()|| Wicket.Browser.isOpera()) { Wicket.replaceOuterHtmlIE(element, text); } else if (Wicket.Browser.isSafari() ) { Wicket.replaceOuterHtmlSafari(element, text); } else { var range = element.ownerDocument.createRange(); range.selectNode(element); var fragment = range.createContextualFragment(text); element.parentNode.replaceChild(fragment, element); } } Wicket.decode = function(encoding, text) { if (encoding == "wicket1") { return Wicket.decode1(text); } } Wicket.decode1 = function(text) { return Wicket.replaceAll(text, "]^", "]"); } Wicket.replaceAll = function(str, from, to) { eval('var regex = /' + from.replace( /\W/g ,'\\$&' ) + '/g ;'); return str.replace(regex,to); } Wicket.show=function(e) { var e=Wicket.$(e); if (e!=null) { e.style.display = ""; } } Wicket.hide=function(e) { var e=Wicket.$(e); if (e!=null) { e.style.display = "none"; } } Wicket.showIncrementally=function(e) { var e=Wicket.$(e); if (e==null) return; var count=e.getAttribute("showIncrementallyCount"); count=parseInt((count==null)?0:count); if (count>=0) Wicket.show(e); e.setAttribute("showIncrementallyCount", count+1); } Wicket.hideIncrementally=function(e) { var e=Wicket.$(e); if (e==null) return; var count=e.getAttribute("showIncrementallyCount"); count=parseInt((count==null)?0:count-1); if (count<=0) Wicket.hide(e); e.setAttribute("showIncrementallyCount", count); } Wicket.Form = { } Wicket.Form.encode = function(text) { if (encodeURIComponent) { return encodeURIComponent(text); } else { return escape(text); } } Wicket.Form.serializeSelect = function(select){ if (select.multiple == false){ return Wicket.Form.encode(select.name) + "=" + Wicket.Form.encode(select.value) + "&"; } var result = ""; for (var i = 0; i < select.options.length; ++i) { var option = select.options[i]; if (option.selected) { result += Wicket.Form.encode(select.name) + "=" + Wicket.Form.encode(option.value) + "&"; } } return result; } Wicket.Form.serializeInput = function(input) { var type = input.type.toLowerCase(); if ((type == "checkbox" || type == "radio") && input.checked) { return Wicket.Form.encode(input.name) + "=" + Wicket.Form.encode(input.value) + "&"; } else if (type == "text" || type == "password" || type == "hidden" || type == "textarea" || type == "search") { return Wicket.Form.encode(input.name) + "=" + Wicket.Form.encode(input.value) + "&"; } else { return ""; } } Wicket.Form.excludeFromAjaxSerialization = {}; Wicket.Form.serializeElement = function(e) { if (Wicket.Form.excludeFromAjaxSerialization && e.id && Wicket.Form.excludeFromAjaxSerialization[e.id] == "true") { return ""; } var tag = e.tagName.toLowerCase(); if (tag == "select") { return Wicket.Form.serializeSelect(e); } else if (tag == "input" || tag == "textarea") { return Wicket.Form.serializeInput(e); } else { return ""; } } Wicket.Form.doSerialize = function(form) { var result = ""; for (var i = 0; i < form.elements.length; ++i) { var e = form.elements[i]; if (e.name && e.name != "" && !e.disabled) { result += Wicket.Form.serializeElement(e); } } return result; } Wicket.Form.serialize = function(element, dontTryToFindRootForm) { if (element.tagName.toLowerCase() == "form") { return Wicket.Form.doSerialize(element); } else { var elementBck = element; if (dontTryToFindRootForm != true) { do { element = element.parentNode; } while(element.tagName.toLowerCase() != "form" && element.tagName.toLowerCase() != "body") } if (element.tagName.toLowerCase() == "form"){ return Wicket.Form.doSerialize(element); } else { var form = document.createElement("form"); var parent = elementBck.parentNode; parent.replaceChild(form, elementBck); form.appendChild(elementBck); var result = Wicket.Form.doSerialize(form); parent.replaceChild(elementBck, form); return result } } } Wicket.DOM = { } Wicket.DOM.serializeNodeChildren = function(node) { if (node == null) { return "" } var result = ""; for (var i = 0; i < node.childNodes.length; i++) { var thisNode = node.childNodes[i]; switch (thisNode.nodeType) { case 1: case 5: result += Wicket.DOM.serializeNode(thisNode); break; case 8: result += ""; break; case 4: result += ""; break; case 3: case 2: result += thisNode.nodeValue; break; default: break; } } return result; } Wicket.DOM.serializeNode = function(node){ if (node == null) { return "" } var result = ""; result += '<' + node.nodeName; if (node.attributes && node.attributes.length > 0) { for (var i = 0; i < node.attributes.length; i++) { result += " " + node.attributes[i].name + "=\"" + node.attributes[i].value + "\""; } } result += '>'; result += Wicket.DOM.serializeNodeChildren(node); result += ''; return result; } Wicket.DOM.containsElement = function(element) { var id = element.getAttribute("id"); if (id != null) return Wicket.$(id) != null; else return false; } Wicket.Channel = Wicket.Class.create(); Wicket.Channel.prototype = { initialize: function(name) { var res = name.match(/^([^|]+)\|(d|s)$/) if (res == null) this.type ='s'; else this.type = res[2]; this.callbacks = new Array(); this.busy = false; }, schedule: function(callback) { if (this.busy == false) { this.busy = true; return callback(); } else { Wicket.Log.info("Channel busy - postponing..."); if (this.type == 's') this.callbacks.push(callback); else this.callbacks[0] = callback; return null; } }, done: function() { var c = null; if (this.callbacks.length > 0) { c = this.callbacks.shift(); } if (c != null && typeof(c) != "undefined") { Wicket.Log.info("Calling posponed function..."); window.setTimeout(c, 1); } else { this.busy = false; } } }; Wicket.ChannelManager = Wicket.Class.create(); Wicket.ChannelManager.prototype = { initialize: function() { this.channels = new Array(); }, schedule: function(channel, callback) { var c = this.channels[channel]; if (c == null) { c = new Wicket.Channel(channel); this.channels[channel] = c; } return c.schedule(callback); }, done: function(channel) { var c = this.channels[channel]; if (c != null) c.done(); } }; Wicket.channelManager = new Wicket.ChannelManager(); Wicket.Ajax = { createTransport: function() { var transport = null; if (window.ActiveXObject) { transport = new ActiveXObject("Microsoft.XMLHTTP"); Wicket.Log.info("Using ActiveX transport"); } else if (window.XMLHttpRequest) { transport = new XMLHttpRequest(); Wicket.Log.info("Using XMLHttpRequest transport"); } if (transport == null) { Wicket.Log.error("Wicket.Ajax.createTransport: Could not locate ajax transport. Your browser does not support the required XMLHttpRequest object or wicket could not gain access to it."); } return transport; }, transports: [], getTransport: function() { var t = Wicket.Ajax.transports; for (var i = 0; i < t.length; ++i) { if (t[i].readyState == 0) { return t[i]; } } t.push(Wicket.Ajax.createTransport()); return t[t.length-1]; }, preCallHandlers: [], postCallHandlers: [], failureHandlers: [], registerPreCallHandler: function(handler) { var h = Wicket.Ajax.preCallHandlers; h.push(handler); }, registerPostCallHandler: function(handler) { var h = Wicket.Ajax.postCallHandlers; h.push(handler); }, registerFailureHandler: function(handler) { var h = Wicket.Ajax.failureHandlers; h.push(handler); }, invokePreCallHandlers: function() { var h = Wicket.Ajax.preCallHandlers; if (h.length > 0) { Wicket.Log.info("Invoking pre-call handler(s)..."); } for (var i = 0; i < h.length; ++i) { h[i](); } }, invokePostCallHandlers: function() { var h = Wicket.Ajax.postCallHandlers; if (h.length > 0) { Wicket.Log.info("Invoking post-call handler(s)..."); } for (var i = 0; i < h.length; ++i) { h[i](); } }, invokeFailureHandlers: function() { var h = Wicket.Ajax.failureHandlers; if (h.length > 0) { Wicket.Log.info("Invoking failure handler(s)..."); } for (var i = 0; i < h.length; ++i) { h[i](); } } } Wicket.Ajax.Request = Wicket.Class.create(); Wicket.Ajax.Request.prototype = { initialize: function(url, loadedCallback, parseResponse, randomURL, failureHandler, channel, successHandler) { this.url = url; this.loadedCallback = loadedCallback; this.parseResponse = parseResponse != null ? parseResponse : true; this.randomURL = randomURL != null ? randomURL : true; this.failureHandler = failureHandler != null ? failureHandler : function() { }; this.successHandler = successHandler != null ? successHandler : function() { }; this.async = true; this.channel = channel; this.precondition = function() { return true; } this.suppressDone = false; this.instance = Math.random(); this.debugContent = true; }, done: function() { Wicket.channelManager.done(this.channel); }, createUrl: function() { if (this.randomURL == false) return this.url; else return this.url + (this.url.indexOf("?")>-1 ? "&" : "?") + "random=" + Math.random(); }, log: function(method, url) { var log = Wicket.Log.info; log(""); log("Initiating Ajax "+method+" request on " + url); }, failure: function() { this.failureHandler(); Wicket.Ajax.invokePostCallHandlers(); Wicket.Ajax.invokeFailureHandlers(); }, get: function() { if (Wicket.isPortlet()) { var qs = this.url.indexOf('?'); if (qs==-1) { qs = this.url.indexOf('&'); } if (qs>-1) { var query = this.url.substring(qs+1); if (query && query.length > 0) { this.url = this.url.substring(0,qs); if (query.charAt(query.length-1)!='&') { query += "&"; } return this.post(query); } } } if (this.channel != null) { var res = Wicket.channelManager.schedule(this.channel, this.doGet.bind(this)); return res != null ? res : true; } else { return this.doGet(); } }, doGet: function() { if (this.precondition()) { this.transport = Wicket.Ajax.getTransport(); var url = this.createUrl(); this.log("GET", url); Wicket.Ajax.invokePreCallHandlers(); var t = this.transport; if (t != null) { t.open("GET", url, this.async); t.onreadystatechange = this.stateChangeCallback.bind(this); t.setRequestHeader("Wicket-Ajax", "true"); if (typeof(Wicket.Focus.lastFocusId) != "undefined" && Wicket.Focus.lastFocusId != "" && Wicket.Focus.lastFocusId != null) t.setRequestHeader("Wicket-FocusedElementId", Wicket.Focus.lastFocusId); t.setRequestHeader("Accept", "text/xml"); t.send(null); return true; } else { this.failure(); return false; } } else { Wicket.Log.info("Ajax GET stopped because of precondition check, url:" + this.url); this.done(); return true; } }, post: function(body) { if (this.channel != null) { var res = Wicket.channelManager.schedule(this.channel, function() { this.doPost(body); }.bind(this)); return res != null ? res: true; } else { return this.doPost(body); } }, doPost: function(body) { if (this.precondition()) { this.transport = Wicket.Ajax.getTransport(); var url = this.createUrl(); this.log("POST", url); Wicket.Ajax.invokePreCallHandlers(); var t = this.transport; if (t != null) { if (typeof(body) == "function") { body = body(); } t.open("POST", url, this.async); t.onreadystatechange = this.stateChangeCallback.bind(this); t.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); t.setRequestHeader("Wicket-Ajax", "true"); if (typeof(Wicket.Focus.lastFocusId) != "undefined" && Wicket.Focus.lastFocusId != "" && Wicket.Focus.lastFocusId != null) t.setRequestHeader("Wicket-FocusedElementId", Wicket.Focus.lastFocusId); t.setRequestHeader("Accept", "text/xml"); t.send(body); return true; } else { this.failure(); return false; } } else { Wicket.Log.info("Ajax POST stopped because of precondition check, url:" + this.url); this.done(); return true; } }, stateChangeCallback: function() { var t = this.transport; var status; if (t != null && t.readyState == 4) { try { status = t.status; } catch (e) { Wicket.Log.error("Wicket.Ajax.Request.stateChangeCallback: Exception evaluating AJAX status: " + e); status = "unavailable"; } if (status == 200 || status == "") { var responseAsText = t.responseText; var redirectUrl; try { redirectUrl = t.getResponseHeader('Ajax-Location'); } catch (ignore) { } if (typeof(redirectUrl) != "undefined" && redirectUrl != null && redirectUrl != "") { t.onreadystatechange = Wicket.emptyFunction; this.done(); this.successHandler(); if (redirectUrl.charAt(0)==('/')||redirectUrl.match("^http://")=="http://"||redirectUrl.match("^https://")=="https://") { window.location = redirectUrl; } else { var urlDepth = 0; while (redirectUrl.substring(0, 3) == "../") { urlDepth++; redirectUrl = redirectUrl.substring(3); } var calculatedRedirect = window.location.pathname; while (urlDepth > -1) { urlDepth--; i = calculatedRedirect.lastIndexOf("/"); if (i > -1) { calculatedRedirect = calculatedRedirect.substring(0, i); } } calculatedRedirect += "/" + redirectUrl; if (Wicket.Browser.isGecko()) { calculatedRedirect = window.location.protocol + "//" + window.location.host + calculatedRedirect; } window.location = calculatedRedirect; } } else { var log = Wicket.Log.info; log("Received ajax response (" + responseAsText.length + " characters)"); if (this.debugContent != false) { log("\n" + responseAsText); } if (this.parseResponse == true) { var xmldoc; if (typeof(window.XMLHttpRequest) != "undefined" && typeof(DOMParser) != "undefined") { var parser = new DOMParser(); xmldoc = parser.parseFromString(responseAsText, "text/xml"); } else if (window.ActiveXObject) { xmldoc = t.responseXML; } this.loadedCallback(xmldoc); } else { this.loadedCallback(responseAsText); } if (this.suppressDone == false) this.done(); } } else { var log = Wicket.Log.error; log("Received Ajax response with code: " + status); if (status == 500) { log("500 error had text: " + t.responseText); } this.done(); this.failure(); } t.onreadystatechange = Wicket.emptyFunction; t.abort(); this.transport = null; } } }; Wicket.Ajax.Call = Wicket.Class.create(); Wicket.Ajax.Call.prototype = { initialize: function(url, successHandler, failureHandler, channel) { this.successHandler = successHandler != null ? successHandler : function() { }; this.failureHandler = failureHandler != null ? failureHandler : function() { }; var c = channel != null ? channel : "0|s"; this.request = new Wicket.Ajax.Request(url, this.loadedCallback.bind(this), true, true, failureHandler, c, successHandler); this.request.suppressDone = true; }, failure: function(message) { if (message != null) Wicket.Log.error("Wicket.Ajax.Call.failure: Error while parsing response: " + message); this.request.done(); this.failureHandler(); Wicket.Ajax.invokePostCallHandlers(); Wicket.Ajax.invokeFailureHandlers(); }, call: function() { return this.request.get(); }, post: function(body) { return this.request.post(body); }, submitFormById: function(formId, submitButton) { var form = Wicket.$(formId); if (form == null || typeof (form) == "undefined") Wicket.Log.error("Wicket.Ajax.Call.submitFormById: Trying to submit form with id '"+formId+"' that is not in document."); return this.submitForm(form, submitButton); }, submitForm: function(form, submitButton) { if (form.onsubmit) { if (!form.onsubmit()) return; } if (this.handleMultipart(form, submitButton)) { return true; } var body = function() { var s = Wicket.Form.serialize(form); if (submitButton != null) { s += Wicket.Form.encode(submitButton) + "=1"; } return s; } return this.request.post(body); }, handleMultipart: function (form, submitButton) { var multipart=false; if (form.tagName.toLowerCase() != "form") { do { if (multipart==false&&Wicket!=undefined&&Wicket.Forms!=undefined) { var meta=Wicket.Forms[form.id]; if (meta!=undefined) { if (meta["multipart"]!=undefined) { multipart=multipart||meta["multipart"]; } } } form = form.parentNode; } while(form.tagName.toLowerCase() != "form" && form.tagName.toLowerCase() != "body") } if (form.tagName.toLowerCase() != "form") { return false; } multipart=multipart||form.enctype=="multipart/form-data"; if (multipart==false) { return false; } var originalFormAction=form.action; var originalFormTarget=form.target; var originalFormMethod=form.method; var originalFormEnctype=form.enctype; var originalFormEncoding=form.encoding; var iframeName="wicket-submit-"+(""+Math.random()).substr(2); try { var iframe = document.createElement("