mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-23 07:09:20 +01:00
Convert et2_core_xml to TS
This commit is contained in:
parent
5d11d6f34b
commit
4ef29c0c1a
@ -6,10 +6,7 @@
|
|||||||
* @subpackage api
|
* @subpackage api
|
||||||
* @link http://www.egroupware.org
|
* @link http://www.egroupware.org
|
||||||
* @author Andreas Stöckel
|
* @author Andreas Stöckel
|
||||||
* @copyright Stylite 2011
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the given URL asynchronously from the server
|
* Loads the given URL asynchronously from the server
|
||||||
*
|
*
|
||||||
@ -21,84 +18,64 @@
|
|||||||
* @param {object} _context for _callback
|
* @param {object} _context for _callback
|
||||||
* @param {function} _fail_callback function(_xml)
|
* @param {function} _fail_callback function(_xml)
|
||||||
*/
|
*/
|
||||||
function et2_loadXMLFromURL(_url, _callback, _context, _fail_callback)
|
function et2_loadXMLFromURL(_url, _callback, _context, _fail_callback) {
|
||||||
{
|
if (typeof _context == "undefined") {
|
||||||
if (typeof _context == "undefined")
|
_context = null;
|
||||||
{
|
}
|
||||||
_context = null;
|
// use window object from main window with same algorithm as for the template cache
|
||||||
}
|
var win;
|
||||||
|
try {
|
||||||
// use window object from main window with same algorithm as for the template cache
|
if (opener && opener.etemplate2) {
|
||||||
var win;
|
win = opener;
|
||||||
try {
|
}
|
||||||
if (opener && opener.etemplate2)
|
}
|
||||||
{
|
catch (e) {
|
||||||
win = opener;
|
// catch security exception if opener is from a different domain
|
||||||
}
|
}
|
||||||
}
|
if (typeof win == "undefined") {
|
||||||
catch (e) {
|
win = top;
|
||||||
// catch security exception if opener is from a different domain
|
}
|
||||||
}
|
win.jQuery.ajax({
|
||||||
if (typeof win == "undefined")
|
// we add the full url (protocol and domain) as sometimes just the path
|
||||||
{
|
// gives a CSP error interpreting it as file:///path
|
||||||
win = top;
|
// (if there are a enough 404 errors in html content ...)
|
||||||
}
|
url: (_url[0] == '/' ? location.protocol + '//' + location.host : '') + _url,
|
||||||
win.jQuery.ajax({
|
context: _context,
|
||||||
// we add the full url (protocol and domain) as sometimes just the path
|
type: 'GET',
|
||||||
// gives a CSP error interpreting it as file:///path
|
dataType: 'xml',
|
||||||
// (if there are a enough 404 errors in html content ...)
|
success: function (_data, _status, _xmlhttp) {
|
||||||
url: (_url[0]=='/' ? location.protocol+'//'+location.host : '')+_url,
|
_callback.call(_context, _data.documentElement);
|
||||||
context: _context,
|
},
|
||||||
type: 'GET',
|
error: function (_xmlhttp, _err) {
|
||||||
dataType: 'xml',
|
egw().debug('error', 'Loading eTemplate from ' + _url + ' failed! ' + _xmlhttp.status + ' ' + _xmlhttp.statusText);
|
||||||
success: function(_data, _status, _xmlhttp){
|
if (typeof _fail_callback !== 'undefined') {
|
||||||
_callback.call(_context, _data.documentElement);
|
_fail_callback.call(_context, _err);
|
||||||
},
|
}
|
||||||
error: function(_xmlhttp, _err) {
|
}
|
||||||
egw().debug('error', 'Loading eTemplate from '+_url+' failed! '+_xmlhttp.status+' '+_xmlhttp.statusText);
|
});
|
||||||
if(typeof _fail_callback !== 'undefined')
|
|
||||||
{
|
|
||||||
_fail_callback.call(_context, _err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
function et2_directChildrenByTagName(_node, _tagName) {
|
||||||
function et2_directChildrenByTagName(_node, _tagName)
|
// Normalize the tag name
|
||||||
{
|
_tagName = _tagName.toLowerCase();
|
||||||
// Normalize the tag name
|
var result = [];
|
||||||
_tagName = _tagName.toLowerCase();
|
for (var i = 0; i < _node.childNodes.length; i++) {
|
||||||
|
if (_tagName == _node.childNodes[i].nodeName.toLowerCase()) {
|
||||||
var result = [];
|
result.push(_node.childNodes[i]);
|
||||||
for (var i = 0; i < _node.childNodes.length; i++)
|
}
|
||||||
{
|
}
|
||||||
if (_tagName == _node.childNodes[i].nodeName.toLowerCase())
|
return result;
|
||||||
{
|
|
||||||
result.push(_node.childNodes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
function et2_filteredNodeIterator(_node, _callback, _context) {
|
||||||
function et2_filteredNodeIterator(_node, _callback, _context)
|
for (var i = 0; i < _node.childNodes.length; i++) {
|
||||||
{
|
var node = _node.childNodes[i];
|
||||||
for (var i = 0; i < _node.childNodes.length; i++)
|
var nodeName = node.nodeName.toLowerCase();
|
||||||
{
|
if (nodeName.charAt(0) != "#") {
|
||||||
var node = _node.childNodes[i];
|
_callback.call(_context, node, nodeName);
|
||||||
var nodeName = node.nodeName.toLowerCase();
|
}
|
||||||
if (nodeName.charAt(0) != "#")
|
}
|
||||||
{
|
|
||||||
_callback.call(_context, node, nodeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
function et2_readAttrWithDefault(_node, _name, _default) {
|
||||||
function et2_readAttrWithDefault(_node, _name, _default)
|
var val = _node.getAttribute(_name);
|
||||||
{
|
return (val === null) ? _default : val;
|
||||||
var val = _node.getAttribute(_name);
|
|
||||||
|
|
||||||
return (val === null) ? _default : val;
|
|
||||||
}
|
}
|
||||||
|
//# sourceMappingURL=et2_core_xml.js.map
|
||||||
|
|
103
api/js/etemplate/et2_core_xml.ts
Normal file
103
api/js/etemplate/et2_core_xml.ts
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/**
|
||||||
|
* EGroupware eTemplate2 - JS XML Code
|
||||||
|
*
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||||
|
* @package etemplate
|
||||||
|
* @subpackage api
|
||||||
|
* @link http://www.egroupware.org
|
||||||
|
* @author Andreas Stöckel
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given URL asynchronously from the server
|
||||||
|
*
|
||||||
|
* We make the Ajax call through main-windows jQuery object, to ensure cached copy
|
||||||
|
* in main-windows etemplate2 prototype works in IE too!
|
||||||
|
*
|
||||||
|
* @param {string} _url
|
||||||
|
* @param {function} _callback function(_xml)
|
||||||
|
* @param {object} _context for _callback
|
||||||
|
* @param {function} _fail_callback function(_xml)
|
||||||
|
*/
|
||||||
|
function et2_loadXMLFromURL(_url : string, _callback : Function, _context : object, _fail_callback : Function)
|
||||||
|
{
|
||||||
|
if (typeof _context == "undefined")
|
||||||
|
{
|
||||||
|
_context = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use window object from main window with same algorithm as for the template cache
|
||||||
|
let win;
|
||||||
|
try {
|
||||||
|
if (opener && opener.etemplate2)
|
||||||
|
{
|
||||||
|
win = opener;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// catch security exception if opener is from a different domain
|
||||||
|
}
|
||||||
|
if (typeof win == "undefined")
|
||||||
|
{
|
||||||
|
win = top;
|
||||||
|
}
|
||||||
|
win.jQuery.ajax({
|
||||||
|
// we add the full url (protocol and domain) as sometimes just the path
|
||||||
|
// gives a CSP error interpreting it as file:///path
|
||||||
|
// (if there are a enough 404 errors in html content ...)
|
||||||
|
url: (_url[0]=='/' ? location.protocol+'//'+location.host : '')+_url,
|
||||||
|
context: _context,
|
||||||
|
type: 'GET',
|
||||||
|
dataType: 'xml',
|
||||||
|
success: function(_data, _status, _xmlhttp){
|
||||||
|
_callback.call(_context, _data.documentElement);
|
||||||
|
},
|
||||||
|
error: function(_xmlhttp, _err) {
|
||||||
|
egw().debug('error', 'Loading eTemplate from '+_url+' failed! '+_xmlhttp.status+' '+_xmlhttp.statusText);
|
||||||
|
if(typeof _fail_callback !== 'undefined')
|
||||||
|
{
|
||||||
|
_fail_callback.call(_context, _err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function et2_directChildrenByTagName(_node : HTMLElement, _tagName : String) : HTMLElement[]
|
||||||
|
{
|
||||||
|
// Normalize the tag name
|
||||||
|
_tagName = _tagName.toLowerCase();
|
||||||
|
|
||||||
|
let result = [];
|
||||||
|
for (let i = 0; i < _node.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (_tagName == _node.childNodes[i].nodeName.toLowerCase())
|
||||||
|
{
|
||||||
|
result.push(_node.childNodes[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function et2_filteredNodeIterator(_node : HTMLElement, _callback : Function, _context : object)
|
||||||
|
{
|
||||||
|
for (let i = 0; i < _node.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
let node = _node.childNodes[i];
|
||||||
|
let nodeName = node.nodeName.toLowerCase();
|
||||||
|
if (nodeName.charAt(0) != "#")
|
||||||
|
{
|
||||||
|
_callback.call(_context, node, nodeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function et2_readAttrWithDefault(_node : HTMLElement, _name : string, _default : string) : string
|
||||||
|
{
|
||||||
|
let val = _node.getAttribute(_name);
|
||||||
|
|
||||||
|
return (val === null) ? _default : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user