~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/contrib/slimmer/tests/moo.ajax.js

  • Committer: Steve Alexander
  • Date: 2007-03-31 20:46:51 UTC
  • mto: (3847.2.91 onezero-ui-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4046.
  • Revision ID: steve.alexander@canonical.com-20070331204651-8gpspx5ya2jqbvxz
add slimmer CSS compressor to contrib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//based on prototype's ajax class
 
2
//to be used with prototype.lite, moofx.mad4milk.net.
 
3
 
 
4
ajax = Class.create();
 
5
ajax.prototype = {
 
6
        initialize: function(url, options){
 
7
                this.transport = this.getTransport();
 
8
                this.postBody = options.postBody || '';
 
9
                this.method = options.method || 'post';
 
10
                this.onComplete = options.onComplete || null;
 
11
                this.update = $(options.update) || null;
 
12
                this.request(url);
 
13
        },
 
14
 
 
15
        request: function(url){
 
16
                this.transport.open(this.method, url, true);
 
17
                this.transport.onreadystatechange = this.onStateChange.bind(this);
 
18
                if (this.method == 'post') {
 
19
                        this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
 
20
                        if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
 
21
                }
 
22
                this.transport.send(this.postBody);
 
23
        },
 
24
 
 
25
        onStateChange: function(){
 
26
                if (this.transport.readyState == 4 && this.transport.status == 200) {
 
27
                        if (this.onComplete) 
 
28
                                setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
 
29
                        if (this.update)
 
30
                                setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
 
31
                        this.transport.onreadystatechange = function(){};
 
32
                }
 
33
        },
 
34
 
 
35
        getTransport: function() {
 
36
                if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
 
37
                else if (window.XMLHttpRequest) return new XMLHttpRequest();
 
38
                else return false;
 
39
        }
 
40
};
 
 
b'\\ No newline at end of file'