~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/build/get-nodejs/get-nodejs-debug.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.5.0 (build 5089)
3
 
Copyright 2012 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('get-nodejs', function(Y) {
8
 
 
9
 
    /**
10
 
    * NodeJS specific Get module used to load remote resources. It contains the same signature as the default Get module so there is no code change needed.
11
 
    * Note: There is an added method called Get.domScript, which is the same as Get.script in a browser, it simply loads the script into the dom tree
12
 
    * so that you can call outerHTML on the document to print it to the screen.
13
 
    * @module get-nodejs
14
 
    */
15
 
 
16
 
        var path = require('path');
17
 
 
18
 
        Y.config.base = path.join(__dirname, '../');
19
 
        console.log(Y.config);
20
 
 
21
 
        YUI.add('get', function() { });
22
 
        
23
 
        var end = function(cb, msg, result) {
24
 
            //Y.log('Get end: ' + cb.onEnd);
25
 
            if (Y.Lang.isFunction(cb.onEnd)) {
26
 
                cb.onEnd.call(Y, msg, result);
27
 
            }
28
 
        }, pass = function(cb) {
29
 
            //Y.log('Get pass: ' + cb.onSuccess);
30
 
            if (Y.Lang.isFunction(cb.onSuccess)) {
31
 
                cb.onSuccess.call(Y, cb);
32
 
            }
33
 
            end(cb, 'success', 'success');
34
 
        }, fail = function(cb, er) {
35
 
            //Y.log('Get fail: ' + er);
36
 
            if (Y.Lang.isFunction(cb.onFailure)) {
37
 
                cb.onFailure.call(Y, er, cb);
38
 
            }
39
 
            end(cb, er, 'fail');
40
 
        };
41
 
 
42
 
        Y.Get = function() {};
43
 
 
44
 
        /**
45
 
        * Override for Get.script for loading local or remote YUI modules.
46
 
        */
47
 
        Y.Get.script = function(s, cb) {
48
 
            var A = Y.Array,
49
 
                urls = A(s), url, i, l = urls.length;
50
 
            for (i=0; i<l; i++) {
51
 
                url = urls[i];
52
 
 
53
 
                url = url.replace(/'/g, '%27');
54
 
                Y.log('URL: ' + url, 'info', 'get');
55
 
                // doesn't need to be blocking, so don't block.
56
 
                include(url, function(err) {
57
 
                    if (!Y.config) {
58
 
                        Y.config = {
59
 
                            debug: true
60
 
                        };
61
 
                    }
62
 
                    Y.log('Loaded: ' + url, 'info', 'get');
63
 
                    if (err) {
64
 
                        Y.log('----------------------------------------------------------', 'error', 'nodejsYUI3');
65
 
                        if (err.stack) {
66
 
                            A.each(err.stack.split('\n'), function(frame) {
67
 
                                Y.log(frame, 'error', 'nodejsYUI3');
68
 
                            });
69
 
                        } else {
70
 
                            console.log(err);
71
 
                        }
72
 
                        Y.log('----------------------------------------------------------', 'error', 'nodejsYUI3');
73
 
                    } else {
74
 
                        pass(cb);
75
 
                    }
76
 
                });
77
 
            }
78
 
        };
79
 
 
80
 
 
81
 
    
82
 
    var vm = require('vm'),
83
 
        fs = require('fs');
84
 
 
85
 
 
86
 
    var include = function(url, cb) {
87
 
        var mod = fs.readFileSync(url, 'utf8');
88
 
        var script = vm.createScript(mod, url);
89
 
        var box = {
90
 
            YUI: {
91
 
                add: function() {
92
 
                    console.log('YUI in the sandbox');
93
 
                    console.log(arguments);
94
 
                    YUI.apply(YUI, arguments);
95
 
                    cb();
96
 
                }
97
 
            }
98
 
        };
99
 
        script.runInNewContext(box);
100
 
        
101
 
    };
102
 
 
103
 
 
104
 
 
105
 
}, '3.5.0' ,{requires:['yui-base']});