Changeset 24061


Ignore:
Timestamp:
2011-05-20T09:32:50+12:00 (13 years ago)
Author:
sjm84
Message:

Several improvements to this Javascript, the search feature is not currently working however

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/gs_ajax_utils.js

    r10695 r24061  
     1/*
     2function loadAsync(sUri, SOAPMessage) {
     3    var xmlHttp = XmlHttp.create();
     4    xmlHttp.open("POST", sUri, true);
     5    xmlHttp.onreadystatechange = function () {
     6        if (xmlHttp.readyState == 4){
     7            getTitle2(xmlHttp.responseXML, xmlHttp.responseText);
     8        }     
     9    }
     10    xmlHttp.setRequestHeader("SOAPAction", " ");
     11    xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
    112
     13    xmlHttp.send(SOAPMessage);
     14}
     15*/
    216
    3 function loadAsync(sUri, SOAPMessage) {
    4    var xmlHttp = XmlHttp.create();
    5    var async = true;
    6    xmlHttp.open("POST", sUri, async);
    7    xmlHttp.onreadystatechange = function () {
    8       if (xmlHttp.readyState == 4){
    9         var result = xmlHttp.responseText;
    10             getTitle2(xmlHttp.responseXML, xmlHttp.responseText);
    11     }     
    12    }
    13    xmlHttp.setRequestHeader("SOAPAction", " ");
    14    xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
    15  
    16    xmlHttp.send(SOAPMessage);
     17function messageToSOAP(message) {
     18    return ['<?xml version="1.0" encoding="UTF-8"?>',
     19        '<soapenv:Envelope ',
     20        'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"',
     21        'xmlns:xsd="http://www.w3.org/2001/XMLSchema"',
     22        'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">',
     23            '<soapenv:Body>',
     24                message,
     25            '</soapenv:Body>',
     26        '</soapenv:Envelope>'].join("");
    1727}
    1828
    19 
    20 function messageToSOAP(message) {
    21     soapBody = '<soapenv:Body>' + message + '</soapenv:Body>'
    22     soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' + soapBody + '</soapenv:Envelope>'
    23     x= '<?xml version="1.0" encoding="UTF-8"?>' + soap;
    24     return x;
     29function getText(element) { //get the text from possibly multiple text nodes
     30    if (element.hasChildNodes()) {
     31        var tempString = [];
     32        for (var j = 0; j < element.childNodes.length; j++) {
     33            if (element.childNodes[j].nodeType == Node.TEXT_NODE ) { // =2
     34                tempString.push(element.childNodes[j].nodeValue);
     35            }
     36            else {
     37                tempString.push('non text node: ');
     38            }
     39        }
     40        return tempString.join("");
     41    }
     42    else {
     43        return 'getText: element has no ChildNodes from which to extract Text';
     44    }
    2545}
    2646
    27 
    28 
    29 
    30 function getText(element) { //get the text from possibly multiple text nodes
    31 if (element.hasChildNodes()) {
    32     tempString = '';
    33     for (j=0; j < element.childNodes.length; j++) {
    34                     if (element.childNodes[j].nodeType == Node.TEXT_NODE ) { // =2
    35                         tempString += element.childNodes[j].nodeValue;
    36                     }
    37                     else {
    38                         tempString += 'non text node: ';
    39                     }
    40     }
    41     return tempString;
    42 }
    43 else {
    44     return 'getText: element has no ChildNodes from which to extract Text';
    45 }
    46 }
    47 
    48 
    4947function newOpenTag(name) {
    50     return '<' + name + '>';
     48    return ['<', name, '>'].join("");
    5149}
    5250
    5351function newCloseTag(name) {
    54     return '</' + name + '>';
     52    return ['</', name, '>'].join("");
    5553}
    5654
    5755function newEmptyTag(name) {
    58     return '<' + name + '/>';
     56    return ['<', name, '/>'].join("");
    5957}
    6058
    6159function newElement(name, content) {
    62     e = '<' + name + '>' + content;
    63     e += '</' + name + '>';
    64     return e;
     60    return ['<', name, '>', content, '</', name, '>'].join("");
    6561}
    6662
    67 
    6863function newElementAtt1(name, content, attName, attValue) {
    69     e = '<' + name + ' ' + attName + '="' + attValue +'">' + content;
    70     e += '</' + name + '>';
    71     return e;
     64    return ['<', name, ' ', attName, '="', attValue, '">', content, '</', name, '>'].join("");
    7265}
    7366
    74 
    75 
    76 
    7767function newElementAtt(name, content, nameArray, valueArray) {
    78     e = '<' + name + ' ' ;
    79     for (i=0; i < nameArray.length; i++) {
    80         e += newAttribute(nameArray[i], valueArray[i])
    81     }
    82     e += '>' + content;
    83     e += '</' + name + '>';
    84     return e;
     68    var e = ['<', name, ' '];
     69    for (i=0; i < nameArray.length; i++) {
     70        e.push(newAttribute(nameArray[i], valueArray[i]));
     71    }
     72    e.push(['>', content, '</', name, '>']);
     73    return e.join("");
    8574}
    8675
    87 
    8876function newAttribute(name, value) {
    89                  return ' ' + name + '="' + value + '"';
     77    return [' ', name, '="', value, '"'].join("");
    9078}
    9179
    92 /*
    93 var a = [];
    94 var b = [];
    95 a[0] = 'title';
    96 b[0] = 'test';
    97 a[1] = 'title2';
    98 b[1] = 'test2';
    99 
    100 alert( newElement('message', 'some content', a=[], b=[]));
    101 
    102 */
    103 
    10480function countElementChildren(node) {
    105     count= 0;
    106     childList = node.childNodes;
     81    var count = 0;
     82    var childList = node.childNodes;
    10783    for(var i=0; i < (childList.length); i++) {
    108         childNode = childList.item(i);
     84        var childNode = childList.item(i);
    10985        if ((childNode.nodeType == 1))  { // only count elements
    110                 count++;
     86            count++;
    11187        }
    11288    }
     
    12096}
    12197
    122 
    12398function isElement(node) {
    124     if (node.nodeType == 1) {
    125             return true; }
    126     else {
    127             return false;
    128     }
     99    if (node.nodeType == 1) {
     100        return true; }
     101    else {
     102        return false;
     103    }
    129104}
Note: See TracChangeset for help on using the changeset viewer.