Skip to content

Commit ba9bd1d

Browse files
author
ColinTree
committed
0.3.4: fixed only render when the whole webpage loaded
1 parent 98f0f71 commit ba9bd1d

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

assets/plugin.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ var blockId = 'block0';
2020
require(['gitbook', 'jQuery'], function(gitbook, $) {
2121

2222
gitbook.events.bind("start", function(e, config) {
23-
var conf = config || {};
23+
var conf = config || {"ai2:blocks":{}};
2424
TEXT_WHEN = conf['ai2-blocks']['text_when'] || TEXT_WHEN;
2525
TEXT_DO = conf['ai2-blocks']['text_do'] || TEXT_DO;
2626
TEXT_CALL = conf['ai2-blocks']['text_call'] || TEXT_CALL;
2727
TEXT_SET = conf['ai2-blocks']['text_set'] || TEXT_SET;
2828
SCALE_LEVEL = conf['ai2-blocks']['scale_level'] || SCALE_LEVEL;
29-
29+
30+
render();
31+
});
32+
33+
gitbook.events.bind("page.change", function() {
34+
render();
35+
})
36+
});
37+
38+
function render() {
3039
// METHOD
31-
$('div[ai2-method]').each(function(){
40+
$('div[ai2-method]').filter("[not-rendered]").each(function(){
41+
$(this).removeAttr("not-rendered");
3242
var block = getBlock(decodeURI($(this).attr("value")));
3343

3444
var name = block['name'];
@@ -61,7 +71,8 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
6171
});
6272

6373
// EVENT
64-
$('div[ai2-event]').each(function(){
74+
$('div[ai2-event]').filter("[not-rendered]").each(function(){
75+
$(this).removeAttr("not-rendered");
6576
var block = getBlock(decodeURI($(this).attr("value")));
6677

6778
var name = block['name'];
@@ -93,7 +104,8 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
93104
});
94105

95106
// PROPERTY
96-
$('div[ai2-property]').each(function(){
107+
$('div[ai2-property]').filter("[not-rendered]").each(function(){
108+
$(this).removeAttr("not-rendered");
97109
var block = getBlock(decodeURI($(this).attr("value")));
98110

99111
var name = block['name'];
@@ -127,8 +139,7 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
127139

128140
newBlockAndWorkspace(blockId, scale);
129141
});
130-
});
131-
});
142+
}
132143

133144
/**
134145
* return a required block

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ module.exports = {
77
blocks: {
88
Ai2Method: {
99
process: function(blk) {
10-
return "<div ai2-method value=\""+encodeURI(blk.body)+"\"></div>";
10+
return "<div ai2-method not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
1111
}
1212
},
1313
Ai2Event: {
1414
process: function(blk) {
15-
return "<div ai2-event value=\""+encodeURI(blk.body)+"\"></div>";
15+
return "<div ai2-event not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
1616
}
1717
},
1818
Ai2Property: {
1919
process: function(blk) {
20-
return "<div ai2-property value=\""+encodeURI(blk.body)+"\"></div>";
20+
return "<div ai2-property not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
2121
}
2222
},
2323
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@
5050
"type": "git",
5151
"url": "git+https://github.com/ColinTree/gitbook-plugin-ai2-blocks.git"
5252
},
53-
"version": "0.3.3"
53+
"version": "0.3.4"
5454
}

0 commit comments

Comments
 (0)