forked from YahooArchive/mojito
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (48 loc) · 1.54 KB
/
index.js
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
54
55
56
57
58
59
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*jslint anon:true, sloppy:true*/
/*global YUI*/
YUI.add('LazyLoadBinderIndex', function(Y, NAME) {
Y.namespace('mojito.binders')[NAME] = {
init: function(mojitProxy) {
this.mp = mojitProxy;
},
bind: function(node) {
var my = this;
// immediately load the lazy mojit in my config
this.mp.invoke('load', {
params: {
body: {
mojit: this.mp.config.proxied
}
}
}, function(err, data) {
if (err) {
my.broadcast('lazy-load-error',
{
error: err,
proxied: my.mp.config.proxied
});
} else {
// replace node completely
var markup = Y.JSON.parse(data).lazy;
node.replace(markup);
// notify
my.mp.broadcast('lazy-load-complete',
{
mojit: my.mp.config.proxied
});
// SEPPUKU!! (but leave the node on the DOM)
my.mp.destroySelf(true);
}
});
}
};
}, '0.0.1', {requires: [
'mojito-client',
'node',
'json'
]});