11require ( [ "gitbook" , "jquery" ] , function ( gitbook , $ ) {
2- var matcher = / ( h t t p | h t t p s ) : \/ \/ j s f i d d l e .n e t \/ .+ / ;
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 = / ( h t t p | h t t p s ) : \/ \/ j s f i d d l e .n e t \/ .+ / ;
77+ embedAllLink ( config ) ;
7078 } ) ;
7179
7280 gitbook . events . bind ( "page.change" , function ( ) {
73- embedAllLink ( ) ;
81+ if ( matcher ) {
82+ embedAllLink ( localConfig ) ;
83+ }
7484 } ) ;
7585} ) ;
0 commit comments