Skip to content

Commit e980fe3

Browse files
author
konstantin
committed
add settings for plugins
1 parent 2b608d7 commit e980fe3

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ $ npm install gitbook-plugin-jsfiddle --save
99
```
1010
{
1111
"plugins": [ "jsfiddle"]
12+
"pluginsConfig": {
13+
"jsfiddle":{
14+
"tabs":["result","js","css", "html"],
15+
"height":500,
16+
"widht":500
17+
}
18+
}
1219
}
1320
```
1421
### 3. paste jsfiddle embedded code to you book something like

book/plugin.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require(["gitbook", "jquery"], function (gitbook, $) {
2-
var matcher = /(http|https):\/\/jsfiddle.net\/.+/;
2+
var matcher;
3+
var localConfig = {jsfiddle:{}};
34

45
function getQuery(querystring) {
56
var query = {};
@@ -27,21 +28,25 @@ require(["gitbook", "jquery"], function (gitbook, $) {
2728
return query;
2829
}
2930

30-
function embed(link) {
31+
// <iframe width="100%" height="300" src="http://jsfiddle.net/taucharts/hmvwg1mn/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
32+
function embed(link, config) {
3133
var iframe = document.createElement('iframe'),
32-
url = link.href;
34+
url = link.href.replace(/\?.+/, '') + 'embedded/' + config.tabs.join(',') + '/';
35+
3336
iframe.src = url;
37+
var $frame = $(iframe);
38+
$frame.attr('allowfullscreen', 'allowfullscreen');
39+
$frame.attr('frameborder', 0);
3440
iframe._src = url; // support for google slide embed
3541
iframe.className = link.className; // inherit all the classes from the link
3642
iframe.id = link.id; // also inherit, giving more style control to the user
3743
iframe.style.border = '1px solid #aaa';
3844

3945
var query = getQuery(link.search);
40-
iframe.style.width = query.width || '100%';
41-
iframe.style.minHeight = query.height || '300px';
42-
if (query.height) {
43-
iframe.style.maxHeight = query.height;
44-
}
46+
var widht = query.width || config.width || '100%';
47+
var height = query.height || config.height || '100%';
48+
$frame.attr('width', widht);
49+
$frame.attr('height', height);
4550
link.parentNode.replaceChild(iframe, link);
4651

4752
var onmessage = function (event) {
@@ -57,19 +62,24 @@ require(["gitbook", "jquery"], function (gitbook, $) {
5762
}
5863
}
5964

60-
function embedAllLink() {
65+
function embedAllLink(config) {
66+
localConfig.jsfiddle = config.jsfiddle || {};
67+
localConfig.tabs = config.tabs || ['result'];
6168
$(".book-body a").each(function (index, link) {
6269
if (link.href && matcher.test(link.href)) {
63-
embed(link);
70+
embed(link, localConfig.jsfiddle);
6471
}
6572
});
6673
}
6774

6875
gitbook.events.bind("start", function (e, config) {
69-
embedAllLink();
76+
matcher = /(http|https):\/\/jsfiddle.net\/.+/;
77+
embedAllLink(config);
7078
});
7179

7280
gitbook.events.bind("page.change", function () {
73-
embedAllLink();
81+
if (matcher) {
82+
embedAllLink(localConfig);
83+
}
7484
});
7585
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gitbook-plugin-jsfiddle",
33
"description": "JSFiddle Integration into GitBook",
44
"main": "index.js",
5-
"version": "0.0.1",
5+
"version": "0.0.2",
66
"author": {
77
"name": "Konstantin Krivlenia"
88
},

0 commit comments

Comments
 (0)