/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2011 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.0
@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.0", 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 = [];
/**
* 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 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() {
var methods = [
function() {
return new XMLHttpRequest();
},
function() {
return new ActiveXObject('Msxml2.XMLHTTP');
},
function() {
return new ActiveXObject('Microsoft.XMLHTTP');
}
];
var returnVal;
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.');
};
/**
* Find instance of passed String via getElementById
* @ignore
*/
var $ = function $() {
var results = [], element;
for (var i = 0; i < arguments.length; i++) {
element = arguments[i];
if (typeof element == 'string') {
element = document.getElementById(element);
}
results.push(element);
}
return results.length > 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;
};
/**
* 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
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 = /