/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2013 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notices:
*
* Copyright 2004 The Apache Software Foundation
* Copyright 2004-2008 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
@project JSF JavaScript Library
@version 2.2
@description This is the standard implementation of the JSF JavaScript Library.
*/
/**
* Register with OpenAjax
*/
if (typeof OpenAjax !== "undefined" &&
typeof OpenAjax.hub.registerLibrary !== "undefined") {
OpenAjax.hub.registerLibrary("jsf", "www.sun.com", "2.2", null);
}
// Detect if this is already loaded, and if loaded, if it's a higher version
if (!((jsf && jsf.specversion && jsf.specversion >= 20000 ) &&
(jsf.implversion && jsf.implversion >= 3))) {
/**
* The top level global namespace
* for JavaServer Faces functionality.
* @name jsf
* @namespace
*/
var jsf = {};
/**
* The namespace for Ajax
* functionality.
* @name jsf.ajax
* @namespace
* @exec
*/
jsf.ajax = function() {
var eventListeners = [];
var errorListeners = [];
var delayHandler = null;
/**
* Determine if the current browser is part of Microsoft's failed attempt at
* standards modification.
* @ignore
*/
var isIE = function isIE() {
if (typeof isIECache !== "undefined") {
return isIECache;
}
isIECache =
document.all && window.ActiveXObject &&
navigator.userAgent.toLowerCase().indexOf("msie") > -1 &&
navigator.userAgent.toLowerCase().indexOf("opera") == -1;
return isIECache;
};
var isIECache;
/**
* Determine the version of IE.
* @ignore
*/
var getIEVersion = function getIEVersion() {
if (typeof IEVersionCache !== "undefined") {
return IEVersionCache;
}
if (/MSIE ([0-9]+)/.test(navigator.userAgent)) {
IEVersionCache = parseInt(RegExp.$1);
} else {
IEVersionCache = -1;
}
return IEVersionCache;
}
var IEVersionCache;
/**
* Determine if loading scripts into the page executes the script.
* This is instead of doing a complicated browser detection algorithm. Some do, some don't.
* @returns {boolean} does including a script in the dom execute it?
* @ignore
*/
var isAutoExec = function isAutoExec() {
try {
if (typeof isAutoExecCache !== "undefined") {
return isAutoExecCache;
}
var autoExecTestString = "";
var tempElement = document.createElement('span');
tempElement.innerHTML = autoExecTestString;
var body = document.getElementsByTagName('body')[0];
var tempNode = body.appendChild(tempElement);
if (mojarra && mojarra.autoExecTest) {
isAutoExecCache = true;
delete mojarra.autoExecTest;
} else {
isAutoExecCache = false;
}
deleteNode(tempNode);
return isAutoExecCache;
} catch (ex) {
// OK, that didn't work, we'll have to make an assumption
if (typeof isAutoExecCache === "undefined") {
isAutoExecCache = false;
}
return isAutoExecCache;
}
};
var isAutoExecCache;
/**
* @ignore
*/
var getTransport = function getTransport(context) {
var returnVal;
// Here we check for encoding type for file upload(s).
// This is where we would also include a check for the existence of
// input file control for the current form (see hasInputFileControl
// function) but IE9 (at least) seems to render controls outside of
// form.
if (typeof context !== 'undefined' && context !== null &&
context.includesInputFile &&
context.form.enctype === "multipart/form-data") {
returnVal = new FrameTransport(context);
return returnVal;
}
var methods = [
function() {
return new XMLHttpRequest();
},
function() {
return new ActiveXObject('Msxml2.XMLHTTP');
},
function() {
return new ActiveXObject('Microsoft.XMLHTTP');
}
];
for (var i = 0, len = methods.length; i < len; i++) {
try {
returnVal = methods[i]();
} catch(e) {
continue;
}
return returnVal;
}
throw new Error('Could not create an XHR object.');
};
/**
* Used for iframe based communication (instead of XHR).
* @ignore
*/
var FrameTransport = function FrameTransport(context) {
this.context = context;
this.frame = null;
this.FRAME_ID = "JSFFrameId";
this.FRAME_PARTIAL_ID = "Faces-Request";
this.partial = null;
this.aborted = false;
this.responseText = null;
this.responseXML = null;
this.readyState = 0;
this.requestHeader = {};
this.status = null;
this.method = null;
this.url = null;
this.requestParams = null;
};
/**
* Extends FrameTransport an adds method functionality.
* @ignore
*/
FrameTransport.prototype = {
/**
*@ignore
*/
setRequestHeader:function(key, value) {
if (typeof(value) !== "undefined") {
this.requestHeader[key] = value;
}
},
/**
* Creates the hidden iframe and sets readystate.
* @ignore
*/
open:function(method, url, async) {
this.method = method;
this.url = url;
this.async = async;
this.frame = document.getElementById(this.FRAME_ID);
if (this.frame) {
this.frame.parentNode.removeChild(this.frame);
this.frame = null;
}
if (!this.frame) {
if ((!isIE() && !isIE9Plus())) {
this.frame = document.createElement('iframe');
this.frame.src = "about:blank";
this.frame.id = this.FRAME_ID;
this.frame.name = this.FRAME_ID;
this.frame.type = "content";
this.frame.collapsed = "true";
this.frame.style = "visibility:hidden";
this.frame.width = "0";
this.frame.height = "0";
this.frame.style = "border:0";
this.frame.frameBorder = 0;
document.body.appendChild(this.frame);
this.frame.onload = bind(this, this.callback);
} else {
var div = document.createElement("div");
div.id = "frameDiv";
div.innerHTML = "";
document.body.appendChild(div);
this.frame = document.getElementById(this.FRAME_ID);
this.frame.onload_cb = bind(this, this.callback);
}
}
// Create to send "Faces-Request" param with value "partial/ajax"
// For iframe approach we are sending as request parameter
// For non-iframe (xhr ajax) it is sent in the request header
this.partial = document.createElement("input");
this.partial.setAttribute("type", "hidden");
this.partial.setAttribute("id", this.FRAME_PARTIAL_ID);
this.partial.setAttribute("name", this.FRAME_PARTIAL_ID);
this.partial.setAttribute("value", "partial/ajax");
this.context.form.appendChild(this.partial);
this.readyState = 1;
},
/**
* Sets the form target to iframe, sets up request parameters
* and submits the form.
* @ignore
*/
send:function(data,namingContainerId) {
var evt = {};
this.context.form.target = this.frame.name;
this.context.form.method = this.method;
if (this.url) {
this.context.form.action = this.url;
}
this.readyState = 3;
this.onreadystatechange(evt);
var ddata = decodeURIComponent(data);
var dataArray = ddata.split("&");
var input;
this.requestParams = new Array();
for (var i=0; i 1 ? results : results[0];
};
/**
* Get the form element which encloses the supplied element.
* @param element - element to act against in search
* @returns form element representing enclosing form, or first form if none found.
* @ignore
*/
var getForm = function getForm(element) {
if (element) {
var form = $(element);
while (form) {
if (form.nodeName && (form.nodeName.toLowerCase() == 'form')) {
return form;
}
if (form.form) {
return form.form;
}
if (form.parentNode) {
form = form.parentNode;
} else {
form = null;
}
}
return document.forms[0];
}
return null;
};
/**
* Get the form element which encloses the supplied element
* identified by the supplied identifier.
* @param id - the element id to act against in search
* @returns form element representing enclosing form, or null if not found.
* @ignore
*/
var getFormForId = function getFormForId(id) {
if (id) {
var node = document.getElementById(id);
while (node) {
if (node.nodeName && (node.nodeName.toLowerCase() == 'form')) {
return node;
}
if (node.form) {
return node.form;
}
if (node.parentNode) {
node = node.parentNode;
} else {
node = null;
}
}
}
return null;
};
/**
* Check if a value exists in an array
* @ignore
*/
var isInArray = function isInArray(array, value) {
for (var i = 0; i < array.length; i++) {
if (array[i] === value) {
return true;
}
}
return false;
};
/**
* Evaluate JavaScript code in a global context.
* @param src JavaScript code to evaluate
* @ignore
*/
var globalEval = function globalEval(src) {
if (window.execScript) {
window.execScript(src);
return;
}
// We have to wrap the call in an anon function because of a firefox bug, where this is incorrectly set
// We need to explicitly call window.eval because of a Chrome peculiarity
/**
* @ignore
*/
var fn = function() {
window.eval.call(window,src);
};
fn();
};
/**
* Get all scripts from supplied string, return them as an array for later processing.
* @param str
* @returns {array} of script text
* @ignore
*/
var stripScripts = function stripScripts(str) {
// Regex to find all scripts in a string
var findscripts = /