public
Description: Accessing Google AJAX APIs from server code
Homepage: http://ianloic.com/
Clone URL: git://github.com/ianloic/google-ajax-server.git
Ian McKellar (author)
Thu Mar 20 14:22:48 -0700 2008
google-ajax-server / ajax-environment.js
100644 53 lines (47 sloc) 1.497 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Provide an environment that Google's AJAX APIs are happy to run in.
Copyright 2008 Ian McKellar, under the MIT License */
 
 
/* include John Resig's env.js */
load('env.js');
 
/* debug function */
function debug(msg) { }
//function debug(msg) { print(msg); }
 
/* Implement enough of the W3C Document DOM Object. Not very much. */
var document = {};
document.write = function document_write(html) {
  debug('document.write("'+html+'")');
  m = html.match(/^<script src="(.*)" type="text\/javascript"/);
  if (m) {
    debug('loading: '+m[1]);
    load(m[1]);
  }
}
document.createElement = function document_createElement(tagName) {
  debug('document.createElement("'+tagName+'")');
  if (tagName == 'script') {
    var script = {};
    script.__defineSetter__('type',
        function(type) { debug('script.type="'+type+'"'); });
    script.__defineSetter__('src',
        function(src) { debug('script.src="'+src+'"');
        load(src);
        });
    return script;
  } else {
    // minimal DOM Element
    var element = {};
    element.appendChild = function(child) { }
    return element;
  }
}
document.getElementsByTagName = function document_getElementsByTagName(tagName) {
  var head = {};
  head.appendChild = function head_appendChild(child) {
    debug('head.appendChild('+child+')');
  }
  debug('document.getElementsByTagName("'+tagName+'")');
  return [head];
}
 
/* just enough timeout support... */
function clearTimeout(arg) {
  debug('window.clearTimeout('+arg+')');
}