Last active
December 26, 2015 16:09
-
-
Save shunito/7178478 to your computer and use it in GitHub Desktop.
BeBeはBiB/i の薄いラッパーです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Bebe | |
is a Thin-wrapper for BiB/i | |
BiB/i by @satorumurmur | |
http://sarasa.la/bib/i/ | |
Licensed under the MIT license | |
http://opensource.org/licenses/mit-license.php | |
Copyright | |
@shunito: [email protected] | |
*/ | |
if (typeof BeBe === "undefined") { | |
function BeBe( epub ){ | |
var i = 0, l, id, n, frames; | |
this.EPUB = null; | |
this.list = []; | |
if( !window["bibi-status"] || window["bibi-status"] === "waiting" ) { | |
// もうちょっと待ってね | |
return undefined; | |
} | |
frames = document.getElementsByTagName("iframe"); | |
for(i, l = frames.length; i < l ; i++ ){ | |
if( frames[i].className === "bibi-frame" ) { | |
// ディレクトリ名かEPUBファイル名をIDとしてリスト化 | |
// todo: パラメータの最後とは限らないのでちゃんとパース | |
id = frames[i].src; | |
if ( (n = id.lastIndexOf("book=")) != -1 ) { | |
id = id.substring( n+5 ); | |
} | |
if( epub === id ){ | |
this.BiBi = frames[ i ]; | |
this.EPUB = this.BiBi.contentWindow; | |
this.id = id; | |
this.B = this.EPUB.B; | |
this.C = this.EPUB.C; | |
this.R = this.EPUB.R; | |
this.S = this.EPUB.S; | |
} | |
this.list.push( id ); | |
} | |
} | |
// 読み込まれてるEPUBのID(ディレクトリ名かファイル名) | |
this.getID = function(){ | |
return this.id; | |
}; | |
// 読み込まれてるEPUBのID(ディレクトリ名かファイル名)のリスト | |
this.getIDList = function(){ | |
return this.list; | |
}; | |
// EPUBを取得 | |
this.getEpub = function(){ | |
return this.EPUB; | |
}; | |
// 書誌情報を取得 | |
this.getMetadata = function( prop ){ | |
if ( prop ){ | |
return ( this.B.package.metadata[ prop ] ); | |
} | |
return ( this.B.package.metadata ); | |
}; | |
// アイテム情報を取得 | |
this.getItemrefs = function( prop ){ | |
return ( this.B.package.spine.itemrefs ); | |
}; | |
// 表示モードを取得 | |
// book-display-mode | |
// spread-layout-axis | |
// spread-layout-direction | |
// page-progression-direction | |
// page-size-format | |
this.getDisplayMode = function( mode ){ | |
return ( this.S[ mode ]); | |
}; | |
// 表示モードを設定(DisplayMode) | |
this.changeBookDisplayMode = function( mode ){ | |
this.R.changeBookDisplayMode( mode ); | |
return this; | |
}; | |
// 表示モードを設定(SpreadLayoutAxis) | |
this.changeSpreadLayoutAxis = function( mode ){ | |
this.R.changeSpreadLayoutAxis( mode ); | |
return this; | |
}; | |
// 表示モードを設定(PageSizeFormat) | |
this.changePageSizeFormat = function( mode ){ | |
this.R.changePageSizeFormat( mode ); | |
return this; | |
}; | |
// 現在のページを取得 | |
this.getCurrentPage = function(){ | |
var CurrentPages = this.R.getCurrentPages(); | |
return CurrentPages.Start.PageIndex; | |
}; | |
// 総ページ数を取得 | |
this.getPageLength = function(){ | |
if( this.R.Pages ) { return this.R.Pages.length; } | |
return ( null ); | |
}; | |
// 最初のページに移動 | |
this.focusHead = function(){ | |
this.R.focus({ Edge: "head" }); | |
return this; | |
}; | |
// 最後のページに移動 | |
this.focusFoot = function(){ | |
this.R.focus({ Edge: "foot" }); | |
return this; | |
}; | |
// Nページに移動 | |
this.focusPage = function( n ){ | |
this.R.focus( this.R.Pages[n] ); | |
return this; | |
}; | |
// 次のページに移動 | |
this.forward = function(){ | |
this.R.page(+1); | |
return this; | |
}; | |
// 前のページに移動 | |
this.back = function(){ | |
this.R.page(-1); | |
return this; | |
}; | |
// メニューの開閉 | |
this.MenuToggle = function(){ | |
this.C.Switch.Bar.toggle(); | |
return this; | |
}; | |
// フルスクリーン | |
this.FullScreen = function(){ | |
this.C.Switch.FullScreen.click(); | |
return this; | |
}; | |
// EPUBを開く | |
this.open = function(){ | |
var Holder = this.BiBi.parentNode; | |
// 親のクラスに startedがいる場合にはすでに開いている | |
if( Holder.className.indexOf("started") === -1 ){ | |
this.EPUB.document.getElementById("bibi-play").click(); | |
} | |
return this; | |
}; | |
return this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>BeBe Sample</title> | |
<style> | |
h1 { font-size: 120%; } | |
</style> | |
<script src="js/jquery-1.9.1.js"></script> | |
<script> | |
$(function(){ | |
var bebe; | |
setTimeout( function(){ | |
bebe = new BeBe("kusamakura"); | |
if( bebe ){ | |
console.log( bebe.getID() ); | |
console.log( bebe.getMetadata() ); | |
console.log( bebe.getMetadata('title') ); | |
console.log( bebe.getItemrefs() ); | |
console.log( bebe.getPageLength() ); | |
bebe.open().MenuToggle(); | |
} | |
}, 2000); | |
$("#head").on("click", function(){ bebe.focusHead(); }); | |
$("#foot").on("click", function(){ bebe.focusFoot(); }); | |
$("#back").on("click", function(){ bebe.back(); }); | |
$("#forward").on("click", function(){ bebe.forward(); }); | |
$("#menu").on("click", function(){ bebe.MenuToggle(); }); | |
$("#pages").on("click", function(){ console.log( bebe.getPageLength() ); }); | |
$("#num").on("change", function(){ bebe.focusPage( $("#num").val() ); }); | |
}); | |
</script> | |
</head> | |
<body> | |
<header> | |
<h1>BeBe </h1> | |
</header> | |
<section id="stage"> | |
<div class="epub ui-widget-content"> | |
<article id="book2"> | |
<p> | |
<button id="head">|<</button> | |
<button id="back"><</button> | |
<button id="forward">></button> | |
<button id="foot">>|</button> | |
<button id="menu">menu</button> | |
<button id="pages">pageLength</button> | |
<select id="num"> | |
<option value="10">10p</option> | |
<option value="20">20p</option> | |
<option value="30">30p</option> | |
<option value="40">40p</option> | |
</select> | |
</p> | |
<a href="bib/i/?book=kusamakura" data-bibi="embed" data-bibi-style="width: 600px; height: 500px;">Book 2</a> | |
</article> | |
</div><!-- /.epub --> | |
</section> | |
<script src="bib/i.js"></script> | |
<script src="bib/bebe.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment