mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
inital setup/cleaning for v3
This commit is contained in:
parent
1af6322367
commit
b6b48e0b08
430 changed files with 2018 additions and 95437 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@
|
|||
*/**/.DS_Store
|
||||
node_modules/
|
||||
components
|
||||
node_modules
|
||||
bower_components
|
113
API.js
Normal file
113
API.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
// API
|
||||
|
||||
// Epub Rendition
|
||||
// > Package (book)
|
||||
// - Manifest (files)
|
||||
// - Metadata (info)
|
||||
// - Spine (order)
|
||||
// - Navagation (toc)
|
||||
|
||||
// Need to split out rendering and book completely
|
||||
// Something like
|
||||
var epub = ePub("moby-dick.epub");
|
||||
var epub = ePub("s3path/ip/moby-dick.opf");
|
||||
|
||||
var rendition = ePub.Paginate(epub);
|
||||
|
||||
var rendition = ePub.Render.Paginated(book);
|
||||
var rendition = ePub.Render.Scrolling(book);
|
||||
|
||||
ePub.renderer.register(EPUBJS.Paginate);
|
||||
|
||||
// Returns a Scroll Controller, Attachs to a document (or window?)
|
||||
var epub = ePub("moby-dick.epub");
|
||||
|
||||
var epub = ePub();
|
||||
var book = epub.open(_url)
|
||||
return epub
|
||||
|
||||
// Creates a Book Package object, parses manifest
|
||||
var book = epub.open("moby-dick.epub");
|
||||
var book = epub.open("META-INF/container.xml");
|
||||
var book = epub.open("package.opf"); //-- maybe, not in spec?
|
||||
// Set the store
|
||||
|
||||
// Unzip if needed
|
||||
|
||||
// Get the container
|
||||
|
||||
// Get the package path
|
||||
book = new Book("path/to/book/package.opf", store);
|
||||
unpacked = book.unpack();
|
||||
|
||||
return unpacked
|
||||
|
||||
book.unpack()
|
||||
book.manifest
|
||||
book.metadata
|
||||
book.spine
|
||||
book.navigation.toc
|
||||
// book.navigation.landmarks
|
||||
// book.navigation.lot
|
||||
return book
|
||||
|
||||
// Loads a chapter of the Book
|
||||
var section = book.spine.get(1);
|
||||
var section = book.spine.get("chap1.html");
|
||||
var section = book.spine.get("#id1234");
|
||||
|
||||
// Alias for spine
|
||||
var section = book.section("epubcfi(/6/30[id-id2640702])");
|
||||
var section = book.section(1);
|
||||
|
||||
book.loaded.navigation.then()
|
||||
book.navigation.get()
|
||||
book.navigation.get("#toc-chap-1")
|
||||
book.navigation.get("chap1.html")
|
||||
|
||||
// Returns the straight html of the chapter
|
||||
//-- When does the chapter content processing happen?
|
||||
section.render()
|
||||
|
||||
// Returns a new renderer
|
||||
var rendition = epub.renderer(book, type);
|
||||
return new Renderer(book, type)
|
||||
|
||||
// Render to a div
|
||||
rendition.attachTo("elementID");
|
||||
// or
|
||||
body.appendChild(rendition.container);
|
||||
|
||||
// Display the provided chapter
|
||||
rendition.display(chapter);
|
||||
|
||||
// Rendering sugar ?
|
||||
epub.renderTo("elementID", _type);
|
||||
rendition = epub.renderer(book, _type);
|
||||
rendition.attachTo("elementID");
|
||||
epub.display();
|
||||
return rendition;
|
||||
|
||||
epub.display();
|
||||
epub.display(1);
|
||||
epub.display("chapt1.html#something");
|
||||
epub.display("epubcfi(/6/30[id-id2640702]!2/4/1:0)");
|
||||
section = book.section(_arg);
|
||||
rendition.display(section);
|
||||
section.render();
|
||||
section.load();
|
||||
return rendition;
|
||||
|
||||
epub.rendition.backwards();
|
||||
epub.rendition.forwards();
|
||||
|
||||
epub.rendition.addStyle();
|
||||
epub.rendition.addStyles();
|
||||
|
||||
|
||||
epub.find("query");
|
||||
section.find("query");
|
||||
|
||||
epub.on("noAuth", function(){
|
||||
|
||||
});
|
86
Gruntfile.js
86
Gruntfile.js
|
@ -2,91 +2,31 @@ module.exports = function(grunt) {
|
|||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
pkg: '<json:package.json>',
|
||||
meta: {
|
||||
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
|
||||
'<%= grunt.template.today("yyyy-mm-dd") %> */'
|
||||
},
|
||||
concat_sourcemap : {
|
||||
'build/epub_no_underscore.js': ['<banner>', 'libs/rsvp/rsvp.js', 'src/*.js'],
|
||||
'build/epub.js': ['<banner>', 'libs/underscore/underscore-min.js', 'libs/rsvp/rsvp.js', 'src/*.js'],
|
||||
'build/reader.js': ['<banner>', 'reader_src/reader.js', 'reader_src/controllers/*.js'],
|
||||
'build/hooks.js': ['<banner>', 'hooks/default/*.js']
|
||||
},
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
uglify: {
|
||||
my_target: {
|
||||
options: {
|
||||
preserveComments: 'some',
|
||||
sourceMap: true
|
||||
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
|
||||
},
|
||||
files: {
|
||||
'build/epub.min.js': ['build/epub.js'],
|
||||
'build/reader.min.js': ['build/reader.js'],
|
||||
'build/hooks.min.js': ['build/hooks.js'],
|
||||
'build/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'],
|
||||
'build/libs/inflate.js': ['libs/zip/inflate.js']
|
||||
}
|
||||
build: {
|
||||
src: 'src/<%= pkg.name %>.js',
|
||||
dest: 'build/<%= pkg.name %>.min.js'
|
||||
}
|
||||
},
|
||||
copy: {
|
||||
main: {
|
||||
files: [
|
||||
{src: 'build/epub.js', dest: 'reader/js/epub.min.js'},
|
||||
{src: 'build/hooks.min.js', dest: 'reader/js/hooks.min.js'},
|
||||
{src: 'build/reader.min.js', dest: 'reader/js/reader.min.js'},
|
||||
{src: 'build/epub.min.map', dest: 'reader/js/epub.js.map'},
|
||||
{src: 'build/hooks.min.map', dest: 'reader/js/hooks.js.map'},
|
||||
{src: 'build/reader.js.map', dest: 'reader/js/hooks.js.map'},
|
||||
{src: 'build/zip/*', dest: 'reader/js/libs/', filter: 'isFile'},
|
||||
{src: 'libs/jquery/jquery-2.1.0.min.js', dest:'reader/js/libs/jquery-2.1.0.min.js'},
|
||||
{src: 'libs/screenfull.min.js', dest: 'reader/js/libs/screenfull.min.js'},
|
||||
{src: 'reader_src/plugins/search.js', dest: 'reader/js/plugins/search.js'},
|
||||
{src: 'reader_src/plugins/hypothesis.js', dest: 'reader/js/plugins/hypothesis.js'},
|
||||
{src: 'hooks/extensions/highlight.js', dest: 'reader/js/hooks/extensions/highlight.js'}
|
||||
|
||||
]
|
||||
},
|
||||
},
|
||||
jshint: {
|
||||
all: ['src/**/*.js'],//, 'reader/**/*.js']
|
||||
connect: {
|
||||
server: {
|
||||
options: {
|
||||
// Environments
|
||||
"browser": true,
|
||||
"devel": true,
|
||||
"worker": true,
|
||||
|
||||
// Enforcing
|
||||
//"maxlen": 80,
|
||||
//"quotmark": "single",
|
||||
"trailing": true,
|
||||
"strict": false,
|
||||
|
||||
// Relaxing
|
||||
"boss": true,
|
||||
"funcscope": true,
|
||||
"globalstrict": true,
|
||||
"loopfunc": true,
|
||||
"maxerr": 1000,
|
||||
"nonstandard": true,
|
||||
"sub": true,
|
||||
"validthis": true,
|
||||
|
||||
"globals": {
|
||||
"_": false,
|
||||
"define" : false,
|
||||
"module" : false
|
||||
port: 9001,
|
||||
base: '.'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-concat-sourcemap');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
grunt.loadNpmTasks('grunt-contrib-connect');
|
||||
|
||||
// Default task(s).
|
||||
grunt.registerTask('default', ['jshint', 'concat_sourcemap', 'uglify', 'copy']);
|
||||
};
|
||||
grunt.registerTask('default', ['uglify']);
|
||||
grunt.registerTask('serve', ['connect']);
|
||||
|
||||
};
|
186
README.md
186
README.md
|
@ -1,186 +0,0 @@
|
|||
Epub.js
|
||||
================================
|
||||
|
||||

|
||||
|
||||
Epub.js is a JavaScript library for rendering ePub documents in the browser, across many devices.
|
||||
|
||||
Epub.js provides an interface for common ebook functions (such as rendering, persistence and pagination) without the need to develop a dedicated application or plugin. Importantly, it has an incredibly permissive [Free BSD](http://en.wikipedia.org/wiki/BSD_licenses) license.
|
||||
|
||||
[Try it while reading Moby Dick](http://futurepress.github.com/epub.js/reader/)
|
||||
|
||||
|
||||
Why EPUB
|
||||
-------------------------
|
||||
|
||||

|
||||
|
||||
The [EPUB standard](http://www.idpf.org/epub/30/spec/epub30-overview.html) is a widely used and easily convertible format. Many books are currently in this format, and it is convertible to many other formats (such as PDF, Mobi and iBooks).
|
||||
|
||||
An unzipped ePUB3 is a collection of HTML5 files, CSS, images and other media – just like any other website. However, it enforces a schema of book components, which allows us to render a book and its parts based on a controlled vocabulary.
|
||||
|
||||
More specifically, the ePUB schema standardizes the table of contents, provides a manifest that enables the caching of the entire book, and separates the storage of the content from how it’s displayed.
|
||||
|
||||
Getting Started
|
||||
-------------------------
|
||||
|
||||
Get the minified code from the build folder:
|
||||
|
||||
```html
|
||||
<script src="../build/epub.min.js"></script>
|
||||
```
|
||||
|
||||
If you plan on using compressed (zipped) epubs (any .epub file) include the minified version of [zip.js](http://gildas-lormeau.github.io/zip.js/)
|
||||
|
||||
Also make sure to set ```EPUBJS.filePath``` to the directory containing ```inflate.js```
|
||||
|
||||
```html
|
||||
<!-- Zip JS -->
|
||||
<script src="/build/libs/zip.min.js"></script>
|
||||
|
||||
<script>
|
||||
EPUBJS.filePath = "../build/libs/";
|
||||
</script>
|
||||
```
|
||||
|
||||
Setup a element to render to:
|
||||
|
||||
```html
|
||||
<div onclick="Book.prevPage();">‹</div>
|
||||
<div id="area"></div>
|
||||
<div onclick="Book.nextPage();">›</div>
|
||||
```
|
||||
|
||||
Create the new ePub, and then render it to that element:
|
||||
|
||||
```html
|
||||
<script>
|
||||
var Book = ePub("url/to/book/");
|
||||
Book.renderTo("area");
|
||||
</script>
|
||||
```
|
||||
|
||||
See the [Documentation](https://github.com/futurepress/epub.js/blob/master/documentation/README.md) to view events and methods for getting the books contents.
|
||||
|
||||
The [Examples](https://github.com/futurepress/epub.js/tree/master/examples) are likely the best place to learn how to use the library.
|
||||
|
||||
|
||||
Recent Updates
|
||||
-------------------------
|
||||
+ v2 splits the render method from the layout and renderer. Currently only iframe rendering is supported, but this change will allow for new render methods in the future. See the breaking changes to the renderer [here](https://github.com/futurepress/epub.js/blob/master/documentation/README.md#renderer).
|
||||
|
||||
+ Work-in-progress pagination support using EPUB page-lists. See a [usage example](http://futurepress.github.io/epub.js/examples/pagination.html). ```renderer:pageChanged``` has changed to ```renderer:locationChanged``` and a ```book:pageChanged``` event was added to pass pagination events.
|
||||
|
||||
+ Moved [Demo Reader](http://futurepress.github.com/epub.js/demo/) to ```/reader/``` and the source to ```/reader_src/```.
|
||||
|
||||
+ Updated CFI handling to support text offsets. CFIs return wrapped like: ```"epubcfi(/6/12[xepigraph_001]!4/2/28/2/1:0)"```. Ranges to be added soon.
|
||||
|
||||
+ Added support for [EPUB properties](http://www.idpf.org/epub/fxl/#property-orientation). This can be overridden in the settings and default to ```{spread: 'reflowable', layout: 'auto', orientation: 'auto'}```
|
||||
|
||||
+ Updated [Documentation](https://github.com/futurepress/epub.js/blob/master/documentation/README.md)
|
||||
|
||||
+ Many more [Tests](http://futurepress.github.io/epub.js/tests/)
|
||||
|
||||
|
||||
Running Locally
|
||||
-------------------------
|
||||
|
||||
install [node.js](http://nodejs.org/)
|
||||
|
||||
install the project dependences with npm
|
||||
```javascript
|
||||
npm install
|
||||
```
|
||||
|
||||
then you can run the reader locally with the command
|
||||
|
||||
```javascript
|
||||
node server.js
|
||||
```
|
||||
|
||||
* [dev.html](http://localhost:8080/reader/dev.html) will pull from the source files and should be used during development.
|
||||
* [index.html](http://localhost:8080/reader/index.html) will use the minified production libraries in the build/ folder.
|
||||
|
||||
Examples
|
||||
-------------------------
|
||||
|
||||
+ [Single](http://futurepress.github.io/epub.js/examples/single.html)
|
||||
+ [Basic](http://futurepress.github.io/epub.js/examples/basic.html)
|
||||
+ [Contained Epub](http://futurepress.github.io/epub.js/examples/contained.html)
|
||||
+ [Promises](http://futurepress.github.io/epub.js/examples/promises.html)
|
||||
+ [Fixed Width & Height](http://futurepress.github.io/epub.js/examples/fixed.html)
|
||||
+ [Custom Element](http://futurepress.github.io/epub.js/examples/custom-elements.html)
|
||||
+ [MathML with MathJAX](http://futurepress.github.io/epub.js/examples/mathml.html)
|
||||
+ [Annotations with Hypothes.is](http://futurepress.github.io/epub.js/examples/hypothesis.html)
|
||||
+ [Pagination](http://futurepress.github.io/epub.js/examples/pagination.html)
|
||||
|
||||
[View All Examples](http://futurepress.github.io/epub.js/examples/)
|
||||
|
||||
Testing
|
||||
-------------------------
|
||||
|
||||
Once you start a server you can run the [QUnit](http://qunitjs.com/) tests at [http://localhost:8080/tests/](http://localhost:8080/tests/)
|
||||
|
||||
You can download the test books from https://github.com/futurepress/books by running:
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
Then you can pull the latest with:
|
||||
```
|
||||
git submodule foreach git pull origin master
|
||||
```
|
||||
|
||||
Building for Distribution
|
||||
-------------------------
|
||||
|
||||
Builds are concatenated and minified using [gruntjs](http://gruntjs.com/getting-started)
|
||||
|
||||
To generate a new build run
|
||||
|
||||
```javascript
|
||||
grunt
|
||||
```
|
||||
|
||||
Hooks
|
||||
-------------------------
|
||||
|
||||
Similar to a plugins, Epub.js implements events that can be "hooked" into. Thus you can interact with and manipulate the contents of the book.
|
||||
|
||||
Examples of this functionality is loading videos from YouTube links before displaying a chapters contents or implementing annotation.
|
||||
|
||||
Hooks require a event to latch onto and a callback for when they are finished.
|
||||
|
||||
Example hook:
|
||||
|
||||
```javascript
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").example = function(callback, renderer){
|
||||
|
||||
var elements = render.doc.querySelectorAll('[video]'),
|
||||
items = Array.prototype.slice.call(elements);
|
||||
|
||||
items.forEach(function(item){
|
||||
//-- do something with the video item
|
||||
}
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Additional Resources
|
||||
-------------------------
|
||||
|
||||
[Epub.js Developer Mailing List](https://groups.google.com/forum/#!forum/epubjs)
|
||||
|
||||
IRC Server: freenode.net Channel: #epub.js
|
||||
|
||||
Follow us on twitter: @Epubjs
|
||||
|
||||
+ http://twitter.com/#!/Epubjs
|
||||
|
||||
Other
|
||||
-------------------------
|
||||
|
||||
EPUB is a registered trademark of the [IDPF](http://idpf.org/).
|
||||
|
31
bower.json
Normal file
31
bower.json
Normal file
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "epubjs",
|
||||
"version": "0.3.0",
|
||||
"authors": [
|
||||
"Fred Chasen <fchasen@gmail.com>"
|
||||
],
|
||||
"description": "Enhanced eBooks in the browser.",
|
||||
"main": "lib/epub.js",
|
||||
"moduleType": [
|
||||
"amd",
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"epub"
|
||||
],
|
||||
"license": "MIT",
|
||||
"homepage": "futurepress.org",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"devDependencies": {
|
||||
"qunit": "~1.14.0",
|
||||
"jquery": "~2.1.1",
|
||||
"rsvp": "~3.0.8"
|
||||
}
|
||||
}
|
7343
build/epub.js
7343
build/epub.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
318
build/hooks.js
318
build/hooks.js
|
@ -1,318 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, renderer){
|
||||
|
||||
var notes = renderer.contents.querySelectorAll('a[href]'),
|
||||
items = Array.prototype.slice.call(notes), //[].slice.call()
|
||||
attr = "epub:type",
|
||||
type = "noteref",
|
||||
folder = EPUBJS.core.folder(location.pathname),
|
||||
cssPath = (folder + EPUBJS.cssPath) || folder,
|
||||
popups = {};
|
||||
|
||||
EPUBJS.core.addCss(cssPath + "popup.css", false, renderer.render.document.head);
|
||||
|
||||
|
||||
items.forEach(function(item){
|
||||
var epubType = item.getAttribute(attr),
|
||||
href,
|
||||
id,
|
||||
el,
|
||||
pop,
|
||||
pos,
|
||||
left,
|
||||
top,
|
||||
txt;
|
||||
|
||||
if(epubType != type) return;
|
||||
|
||||
href = item.getAttribute("href");
|
||||
id = href.replace("#", '');
|
||||
el = renderer.render.document.getElementById(id);
|
||||
|
||||
|
||||
item.addEventListener("mouseover", showPop, false);
|
||||
item.addEventListener("mouseout", hidePop, false);
|
||||
|
||||
function showPop(){
|
||||
var poppos,
|
||||
iheight = renderer.height,
|
||||
iwidth = renderer.width,
|
||||
tip,
|
||||
pop,
|
||||
maxHeight = 225,
|
||||
itemRect;
|
||||
|
||||
if(!txt) {
|
||||
pop = el.cloneNode(true);
|
||||
txt = pop.querySelector("p");
|
||||
}
|
||||
|
||||
// chapter.replaceLinks.bind(this) //TODO:Fred - update?
|
||||
//-- create a popup with endnote inside of it
|
||||
if(!popups[id]) {
|
||||
popups[id] = document.createElement("div");
|
||||
popups[id].setAttribute("class", "popup");
|
||||
|
||||
pop_content = document.createElement("div");
|
||||
|
||||
popups[id].appendChild(pop_content);
|
||||
|
||||
pop_content.appendChild(txt);
|
||||
pop_content.setAttribute("class", "pop_content");
|
||||
|
||||
renderer.render.document.body.appendChild(popups[id]);
|
||||
|
||||
//-- TODO: will these leak memory? - Fred
|
||||
popups[id].addEventListener("mouseover", onPop, false);
|
||||
popups[id].addEventListener("mouseout", offPop, false);
|
||||
|
||||
//-- Add hide on page change
|
||||
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", hidePop);
|
||||
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", offPop);
|
||||
renderer.on("renderer:pageChanged", hidePop, this);
|
||||
renderer.on("renderer:pageChanged", offPop, this);
|
||||
// chapter.book.on("renderer:chapterDestroy", hidePop, this);
|
||||
}
|
||||
|
||||
pop = popups[id];
|
||||
|
||||
|
||||
//-- get location of item
|
||||
itemRect = item.getBoundingClientRect();
|
||||
left = itemRect.left;
|
||||
top = itemRect.top;
|
||||
|
||||
//-- show the popup
|
||||
pop.classList.add("show");
|
||||
|
||||
//-- locations of popup
|
||||
popRect = pop.getBoundingClientRect();
|
||||
|
||||
//-- position the popup
|
||||
pop.style.left = left - popRect.width / 2 + "px";
|
||||
pop.style.top = top + "px";
|
||||
|
||||
|
||||
//-- Adjust max height
|
||||
if(maxHeight > iheight / 2.5) {
|
||||
maxHeight = iheight / 2.5;
|
||||
pop_content.style.maxHeight = maxHeight + "px";
|
||||
}
|
||||
|
||||
//-- switch above / below
|
||||
if(popRect.height + top >= iheight - 25) {
|
||||
pop.style.top = top - popRect.height + "px";
|
||||
pop.classList.add("above");
|
||||
}else{
|
||||
pop.classList.remove("above");
|
||||
}
|
||||
|
||||
//-- switch left
|
||||
if(left - popRect.width <= 0) {
|
||||
pop.style.left = left + "px";
|
||||
pop.classList.add("left");
|
||||
}else{
|
||||
pop.classList.remove("left");
|
||||
}
|
||||
|
||||
//-- switch right
|
||||
if(left + popRect.width / 2 >= iwidth) {
|
||||
//-- TEMP MOVE: 300
|
||||
pop.style.left = left - 300 + "px";
|
||||
|
||||
popRect = pop.getBoundingClientRect();
|
||||
pop.style.left = left - popRect.width + "px";
|
||||
//-- switch above / below again
|
||||
if(popRect.height + top >= iheight - 25) {
|
||||
pop.style.top = top - popRect.height + "px";
|
||||
pop.classList.add("above");
|
||||
}else{
|
||||
pop.classList.remove("above");
|
||||
}
|
||||
|
||||
pop.classList.add("right");
|
||||
}else{
|
||||
pop.classList.remove("right");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function onPop(){
|
||||
popups[id].classList.add("on");
|
||||
}
|
||||
|
||||
function offPop(){
|
||||
popups[id].classList.remove("on");
|
||||
}
|
||||
|
||||
function hidePop(){
|
||||
setTimeout(function(){
|
||||
popups[id].classList.remove("show");
|
||||
}, 100);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
}
|
||||
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").mathml = function(callback, renderer){
|
||||
|
||||
// check of currentChapter properties contains 'mathml'
|
||||
if(renderer.currentChapter.manifestProperties.indexOf("mathml") !== -1 ){
|
||||
|
||||
// Assign callback to be inside iframe window
|
||||
renderer.iframe.contentWindow.mathmlCallback = callback;
|
||||
|
||||
// add MathJax config script tag to the renderer body
|
||||
var s = document.createElement("script");
|
||||
s.type = 'text/x-mathjax-config';
|
||||
s.innerHTML = '\
|
||||
MathJax.Hub.Register.StartupHook("End",function () { \
|
||||
window.mathmlCallback(); \
|
||||
});\
|
||||
MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); \
|
||||
';
|
||||
renderer.doc.body.appendChild(s);
|
||||
// add MathJax.js to renderer head
|
||||
EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML", null, renderer.doc.head);
|
||||
|
||||
} else {
|
||||
if(callback) callback();
|
||||
}
|
||||
}
|
||||
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, renderer){
|
||||
var images = renderer.contents.querySelectorAll('img'),
|
||||
items = Array.prototype.slice.call(images),
|
||||
iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
|
||||
oheight;
|
||||
|
||||
if(renderer.layoutSettings.layout != "reflowable") {
|
||||
callback();
|
||||
return; //-- Only adjust images for reflowable text
|
||||
}
|
||||
|
||||
items.forEach(function(item){
|
||||
|
||||
function size() {
|
||||
var itemRect = item.getBoundingClientRect(),
|
||||
rectHeight = itemRect.height,
|
||||
top = itemRect.top,
|
||||
oHeight = item.getAttribute('data-height'),
|
||||
height = oHeight || rectHeight,
|
||||
newHeight,
|
||||
fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]),
|
||||
fontAdjust = fontSize ? fontSize / 2 : 0;
|
||||
|
||||
iheight = renderer.contents.clientHeight;
|
||||
if(top < 0) top = 0;
|
||||
|
||||
if(height + top >= iheight) {
|
||||
|
||||
if(top < iheight/2) {
|
||||
// Remove top and half font-size from height to keep container from overflowing
|
||||
newHeight = iheight - top - fontAdjust;
|
||||
item.style.maxHeight = newHeight + "px";
|
||||
item.style.width= "auto";
|
||||
}else{
|
||||
if(height > iheight) {
|
||||
item.style.maxHeight = iheight + "px";
|
||||
item.style.width= "auto";
|
||||
itemRect = item.getBoundingClientRect();
|
||||
height = itemRect.height;
|
||||
}
|
||||
item.style.display = "block";
|
||||
item.style["WebkitColumnBreakBefore"] = "always";
|
||||
item.style["breakBefore"] = "column";
|
||||
|
||||
}
|
||||
|
||||
item.setAttribute('data-height', newHeight);
|
||||
|
||||
}else{
|
||||
item.style.removeProperty('max-height');
|
||||
item.style.removeProperty('margin-top');
|
||||
}
|
||||
}
|
||||
|
||||
item.addEventListener('load', size, false);
|
||||
|
||||
renderer.on("renderer:resized", size);
|
||||
|
||||
renderer.on("renderer:chapterUnloaded", function(){
|
||||
item.removeEventListener('load', size);
|
||||
renderer.off("renderer:resized", size);
|
||||
});
|
||||
|
||||
size();
|
||||
|
||||
});
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
}
|
||||
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").transculsions = function(callback, renderer){
|
||||
/*
|
||||
<aside ref="http://www.youtube.com/embed/DUL6MBVKVLI?html5=1" transclusion="video" width="560" height="315">
|
||||
<a href="http://www.youtube.com/embed/DUL6MBVKVLI"> Watch the National Geographic: The Last Roll of Kodachrome</a>
|
||||
</aside>
|
||||
*/
|
||||
|
||||
var trans = renderer.contents.querySelectorAll('[transclusion]'),
|
||||
items = Array.prototype.slice.call(trans);
|
||||
|
||||
items.forEach(function(item){
|
||||
var src = item.getAttribute("ref"),
|
||||
iframe = document.createElement('iframe'),
|
||||
orginal_width = item.getAttribute("width"),
|
||||
orginal_height = item.getAttribute("height"),
|
||||
parent = item.parentNode,
|
||||
width = orginal_width,
|
||||
height = orginal_height,
|
||||
ratio;
|
||||
|
||||
|
||||
function size() {
|
||||
width = orginal_width;
|
||||
height = orginal_height;
|
||||
|
||||
if(width > chapter.colWidth){
|
||||
ratio = chapter.colWidth / width;
|
||||
|
||||
width = chapter.colWidth;
|
||||
height = height * ratio;
|
||||
}
|
||||
|
||||
iframe.width = width;
|
||||
iframe.height = height;
|
||||
}
|
||||
|
||||
|
||||
size();
|
||||
|
||||
//-- resize event
|
||||
|
||||
|
||||
renderer.listenUntil("renderer:resized", "renderer:chapterUnloaded", size);
|
||||
|
||||
iframe.src = src;
|
||||
|
||||
//<iframe width="560" height="315" src="http://www.youtube.com/embed/DUL6MBVKVLI" frameborder="0" allowfullscreen="true"></iframe>
|
||||
parent.replaceChild(iframe, item);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
|
||||
}
|
||||
|
||||
//# sourceMappingURL=hooks.js.map
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "hooks.js",
|
||||
"sources": [
|
||||
"hooks/default/endnotes.js",
|
||||
"hooks/default/mathml.js",
|
||||
"hooks/default/smartimages.js",
|
||||
"hooks/default/transculsions.js"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"
|
||||
}
|
2
build/hooks.min.js
vendored
2
build/hooks.min.js
vendored
|
@ -1,2 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e,f=b.height,j=b.width,p=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.render.document.body.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",h,this),b.on("renderer:pageChanged",g,this)),c=i[k],e=a.getBoundingClientRect(),m=e.left,n=e.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",p>f/2.5&&(p=f/2.5,pop_content.style.maxHeight=p+"px"),popRect.height+n>=f-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=j?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=f-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.layoutSettings.layout?void a():(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(i>e&&(a.style.maxHeight=e+"px",a.style.width="auto",d=a.getBoundingClientRect(),i=d.height),a.style.display="block",a.style.WebkitColumnBreakBefore="always",a.style.breakBefore="column"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),void(a&&a()))},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
||||
//# sourceMappingURL=hooks.min.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
7
build/libs/screenfull.min.js
vendored
7
build/libs/screenfull.min.js
vendored
|
@ -1,7 +0,0 @@
|
|||
/*!
|
||||
* screenfull
|
||||
* v1.1.0 - 2013-09-06
|
||||
* https://github.com/sindresorhus/screenfull.js
|
||||
* (c) Sindre Sorhus; MIT License
|
||||
*/
|
||||
!function(a,b){"use strict";var c="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){for(var a,c,d=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenchange","MSFullscreenerror"]],e=0,f=d.length,g={};f>e;e++)if(a=d[e],a&&a[1]in b){for(e=0,c=a.length;c>e;e++)g[d[0][e]]=a[e];return g}return!1}(),e={request:function(a){var e=d.requestFullscreen;a=a||b.documentElement,/5\.1[\.\d]* Safari/.test(navigator.userAgent)?a[e]():a[e](c&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){b[d.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){},onerror:function(){},raw:d};return d?(Object.defineProperties(e,{isFullscreen:{get:function(){return!!b[d.fullscreenElement]}},element:{enumerable:!0,get:function(){return b[d.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!b[d.fullscreenEnabled]}}}),b.addEventListener(d.fullscreenchange,function(a){e.onchange.call(e,a)}),b.addEventListener(d.fullscreenerror,function(a){e.onerror.call(e,a)}),a.screenfull=e,void 0):(a.screenfull=!1,void 0)}(window,document);
|
30
build/libs/zip.min.js
vendored
30
build/libs/zip.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1124
build/reader.js
1124
build/reader.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
2
build/reader.min.js
vendored
2
build/reader.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,185 +0,0 @@
|
|||
# EPUB.JS Documentation
|
||||
|
||||
## Methods
|
||||
|
||||
#### ePub(bookPath, options)
|
||||
|
||||
Creates a new EPUBJS.Book()
|
||||
|
||||
bookPath is a optional convience method
|
||||
that will start loading the book at that given path
|
||||
```javascript
|
||||
var Book = ePub("url/to/book/"); // With default options
|
||||
```
|
||||
|
||||
```javascript
|
||||
var Book = ePub({ restore: true });
|
||||
Book.open("url/to/book/"); // Books can be opened later
|
||||
```
|
||||
|
||||
Options:
|
||||
|
||||
```javascript
|
||||
{
|
||||
bookPath : null,
|
||||
version: 1, // Changing will cause stored Book information to be reloaded
|
||||
restore: false, // Skips parsing epub contents, loading from localstorage instead
|
||||
storage: false, // true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
|
||||
spreads: true, // Displays two columns
|
||||
fixedLayout : false, //-- Will turn off pagination
|
||||
styles : {}, // Styles to be applied to epub
|
||||
width : false,
|
||||
height: false,
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Intially you'll probably just want to turn on restore.
|
||||
|
||||
The width and height will be set to the containing element's dimensions.
|
||||
|
||||
```javascript
|
||||
var Book = ePub("url/to/book/", { restore: true });
|
||||
```
|
||||
|
||||
The following examples will refer to this ePub variable as ```Book```.
|
||||
|
||||
#### Book.open(bookPath)
|
||||
|
||||
Will open and parse a book at the given path.
|
||||
|
||||
```javascript
|
||||
var Book = ePub({ restore: true });
|
||||
Book.open("url/to/book/"); // Books can be opened later
|
||||
```
|
||||
|
||||
Books can be compressed epub.
|
||||
See section X for additional information about handling these
|
||||
|
||||
```javascript
|
||||
Book.open("url/to/book.epub");
|
||||
```
|
||||
|
||||
|
||||
#### Book.renderTo(element)
|
||||
|
||||
Appends the iframe that will contain the rendered book to a element.
|
||||
|
||||
Returns a promise with the render object after the first chapter has been loaded
|
||||
|
||||
```javascript
|
||||
|
||||
var Book = ePub("url/to/book/", { restore: true });
|
||||
|
||||
var $el = document.getElementById("div-id");
|
||||
Book.renderTo($el);
|
||||
```
|
||||
|
||||
renderTo can take a element id as a string.
|
||||
|
||||
```javascript
|
||||
var Book = ePub("url/to/book/");
|
||||
Book.renderTo("div-id");
|
||||
```
|
||||
|
||||
#### Book.nextPage()
|
||||
#### Book.prevPage()
|
||||
|
||||
Changes the page the book is on.
|
||||
|
||||
If on the first or last page of a chapter, the next chapter will be loaded.
|
||||
|
||||
```html
|
||||
<div onclick="Book.prevPage();">‹</div>
|
||||
<div onclick="Book.nextPage();">›</div>
|
||||
```
|
||||
|
||||
if the book has not been rendered yet, page changes will have no effect.
|
||||
|
||||
#### Book.displayChapter(chap, end)
|
||||
|
||||
Loads book chapter at a given spine position or epub CFI string.
|
||||
|
||||
Returns a promise with the render after the given chapter has been loaded.
|
||||
|
||||
```javascript
|
||||
Book.displayChapter('/6/4[chap01ref]!/4[body01]/10');
|
||||
```
|
||||
|
||||
Setting End to true will advance to the last page of the chapter.
|
||||
|
||||
```javascript
|
||||
Book.displayChapter(3, true);
|
||||
```
|
||||
|
||||
#### Book.goto(url)
|
||||
|
||||
Loads book chapter that has the given url.
|
||||
|
||||
Returns a promise with the render after the given chapter has been loaded
|
||||
|
||||
```javascript
|
||||
var skip = Book.goto("chapter_001.xhtml");
|
||||
skip.then(function(){
|
||||
console.log("On Chapter 1");
|
||||
})
|
||||
```
|
||||
This is often used to create a table of contents, with links to specific chapters.
|
||||
|
||||
#### Book.setStyle(style, val, prefixed)
|
||||
|
||||
Adds style to be attached to the body element rendered book.
|
||||
|
||||
One common use is increasing font-size.
|
||||
|
||||
```javascript
|
||||
Book.setStyle("font-size", "1.2em");
|
||||
```
|
||||
|
||||
#### Book.removeStyle(style)
|
||||
|
||||
Removes a style from the rendered book
|
||||
|
||||
#### Book.destroy()
|
||||
|
||||
Remove the appended iframe and cleans up event listeners.
|
||||
|
||||
### Promises
|
||||
|
||||
#### Book.getMetadata()
|
||||
|
||||
```javascript
|
||||
Book.getMetadata().then(function(meta){
|
||||
document.title = meta.bookTitle+" – "+meta.creator;
|
||||
});
|
||||
```
|
||||
|
||||
#### Book.getToc()
|
||||
|
||||
```javascript
|
||||
Book.getToc().then(function(toc){
|
||||
console.log(toc);
|
||||
});
|
||||
```
|
||||
|
||||
## Events
|
||||
|
||||
book:ready
|
||||
|
||||
book:stored
|
||||
|
||||
book:online
|
||||
|
||||
book:offline
|
||||
|
||||
|
||||
renderer:resized
|
||||
|
||||
renderer:pageChanged
|
||||
|
||||
renderer:chapterDisplayed
|
||||
|
||||
renderer:chapterUnloaded
|
||||
|
||||
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<!-- EPUBJS Renderer -->
|
||||
<!-- zip -->
|
||||
<script src="../libs/zip/zip.js"></script>
|
||||
<script src="../libs/zip/zip-fs.js"></script>
|
||||
<script src="../libs/zip/zip-ext.js"></script>
|
||||
<script src="../libs/zip/inflate.js"></script>
|
||||
<script src="../libs/zip/mime-types.js"></script>
|
||||
|
||||
|
||||
<!-- Render -->
|
||||
<script src="../libs/underscore/underscore.js"></script>
|
||||
<script src="../libs/rsvp/rsvp.js"></script>
|
||||
<script src="../libs/fileStorage/fileStorage.min.js"></script>
|
||||
|
||||
<script src="../src/base.js"></script>
|
||||
<script src="../src/core.js"></script>
|
||||
<script src="../src/unarchiver.js"></script>
|
||||
<script src="../src/parser.js"></script>
|
||||
<script src="../src/hooks.js"></script>
|
||||
<script src="../src/book.js"></script>
|
||||
<script src="../src/chapter.js"></script>
|
||||
<script src="../src/renderer.js"></script>
|
||||
<script src="../src/replace.js"></script>
|
||||
<script src="../src/epubcfi.js"></script>
|
||||
<script src="../src/render_iframe.js"></script>
|
||||
<script src="../src/layout.js"></script>
|
||||
<script src="../src/pagination.js"></script>
|
||||
|
||||
<!-- Hooks -->
|
||||
<!-- <script src="../hooks/default/transculsions.js"></script> -->
|
||||
<!-- <script src="../hooks/default/endnotes.js"></script> -->
|
||||
<script src="../hooks/default/smartimages.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
EPUBJS.filePath = "../reader/js/libs/";
|
||||
EPUBJS.cssPath = "../reader/css/";
|
||||
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
|
||||
}
|
||||
|
||||
#main {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
margin: 5% auto;
|
||||
max-width: 1250px;
|
||||
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#prev {
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
#next {
|
||||
right: 40px;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
margin-top: -32px;
|
||||
font-size: 64px;
|
||||
color: #E2E2E2;
|
||||
font-family: arial, sans-serif;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.arrow:hover {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.arrow:active {
|
||||
color: #000;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
EPUBJS.Render.Iframe.prototype.setLeft = function(leftPos){
|
||||
this.document.documentElement.style.WebkitTransform = "translate(-" + leftPos + "px, 0)";
|
||||
};
|
||||
</script>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader/moby-dick/", {restore: true, reload: true });
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.renderTo("area");
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,102 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>ePubJS Annotator Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="../libs/jquery/jquery-1.9.0.js"></script>
|
||||
|
||||
<!-- Annotator -->
|
||||
<!-- <script src="../libs/annotator/annotator-full.js"></script> -->
|
||||
|
||||
<script src="../libs/annotator/lib/util.js"></script>
|
||||
<script src="../libs/annotator/lib/console.js"></script>
|
||||
<script src="../libs/annotator/lib/class.js"></script>
|
||||
<script src="../libs/annotator/lib/range.js"></script>
|
||||
<script src="../libs/annotator/lib/annotator.js"></script>
|
||||
<script src="../libs/annotator/lib/widget.js"></script>
|
||||
<script src="../libs/annotator/lib/editor.js"></script>
|
||||
<script src="../libs/annotator/lib/viewer.js"></script>
|
||||
<script src="../libs/annotator/lib/notification.js"></script>
|
||||
<script src="../libs/annotator/lib/xpath.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/store.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/permissions.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/annotateitpermissions.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/auth.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/tags.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/unsupported.js"></script>
|
||||
<script src="../libs/annotator/lib/plugin/filter.js"></script>
|
||||
|
||||
<script src="../hooks/extensions/annotate.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="../libs/annotator/css/annotator.css">
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader_src/moby-dick/", { restore: true });
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
<div id="loader"><img src="../reader/img/loader.gif"></div>
|
||||
<select id="toc"></select>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.getMetadata().then(function(meta){
|
||||
|
||||
document.title = meta.bookTitle+" – "+meta.creator;
|
||||
|
||||
});
|
||||
|
||||
Book.getToc().then(function(toc){
|
||||
|
||||
var $select = document.getElementById("toc"),
|
||||
docfrag = document.createDocumentFragment();
|
||||
|
||||
toc.forEach(function(chapter) {
|
||||
var option = document.createElement("option");
|
||||
option.textContent = chapter.label;
|
||||
option.ref = chapter.href;
|
||||
|
||||
docfrag.appendChild(option);
|
||||
});
|
||||
|
||||
$select.appendChild(docfrag);
|
||||
|
||||
$select.onchange = function(){
|
||||
var index = $select.selectedIndex,
|
||||
url = $select.options[index].ref;
|
||||
|
||||
Book.goto(url);
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Book.ready.all.then(function(){
|
||||
document.getElementById("loader").style.display = "none";
|
||||
});
|
||||
|
||||
Book.renderTo("area");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,117 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>ePubJS Promises Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<script src="../libs/underscore/underscore-min.js"></script>
|
||||
<script src="../libs/backbone/backbone-min.js"></script>
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="/build/epub.min.js"></script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("/reader/moby-dick/", { restore: true });
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
<div id="loader"><img src="../reader/img/loader.gif"></div>
|
||||
<select id="toc"></select>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
// Book.getMetadata().then(function(meta){
|
||||
|
||||
// document.title = meta.bookTitle+" – "+meta.creator;
|
||||
|
||||
// });
|
||||
|
||||
// Book.getToc().then(function(toc){
|
||||
|
||||
// var $select = document.getElementById("toc"),
|
||||
// docfrag = document.createDocumentFragment();
|
||||
|
||||
// toc.forEach(function(chapter) {
|
||||
// var option = document.createElement("option");
|
||||
// option.textContent = chapter.label;
|
||||
// option.ref = chapter.href;
|
||||
|
||||
// docfrag.appendChild(option);
|
||||
// });
|
||||
|
||||
// $select.appendChild(docfrag);
|
||||
|
||||
// $select.onchange = function(){
|
||||
// var index = $select.selectedIndex,
|
||||
// url = $select.options[index].ref;
|
||||
|
||||
// Book.goto(url);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// });
|
||||
|
||||
// Book.ready.all.then(function(){
|
||||
// document.getElementById("loader").style.display = "none";
|
||||
// });
|
||||
|
||||
// Book.renderTo("area");
|
||||
|
||||
var BB = {};
|
||||
|
||||
// Router
|
||||
BB.Router = Backbone.Router.extend({
|
||||
routes: {
|
||||
"book/:p" : "details"
|
||||
},
|
||||
|
||||
details: function(hash){
|
||||
var view = new Book.Views.Details({model: Library.get(hash)});
|
||||
view.render(function(el){
|
||||
$("#main").html(el);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Instantiate Router
|
||||
var router = new Book.Router();
|
||||
|
||||
// This will fetch the book template and render it.
|
||||
BB.Views.Details = Backbone.View.extend({
|
||||
template: "app/templates/books/details.html",
|
||||
|
||||
render: function(done) {
|
||||
var view = this;
|
||||
|
||||
// Fetch the template, render it to the View element and call done.
|
||||
namespace.fetchTemplate(this.template, function(tmpl) {
|
||||
view.el.innerHTML = tmpl(view.model.toJSON());
|
||||
|
||||
if (_.isFunction(done)) {
|
||||
done(view.el);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -2,74 +2,29 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<!-- EPUBJS Renderer -->
|
||||
<!-- zip -->
|
||||
<script src="../libs/zip/zip.js"></script>
|
||||
<script src="../libs/zip/zip-fs.js"></script>
|
||||
<script src="../libs/zip/zip-ext.js"></script>
|
||||
<script src="../libs/zip/inflate.js"></script>
|
||||
<script src="../libs/zip/mime-types.js"></script>
|
||||
<title>EPUB.js Basic Example</title>
|
||||
|
||||
<script src="../bower_components/rsvp/rsvp.js"></script>
|
||||
|
||||
<!-- Render -->
|
||||
<script src="../libs/underscore/underscore.js"></script>
|
||||
<script src="../libs/rsvp/rsvp.js"></script>
|
||||
<script src="../libs/fileStorage/fileStorage.min.js"></script>
|
||||
|
||||
<script src="../src/base.js"></script>
|
||||
<script src="../src/core.js"></script>
|
||||
<script src="../src/unarchiver.js"></script>
|
||||
<script src="../src/parser.js"></script>
|
||||
<script src="../src/hooks.js"></script>
|
||||
<script src="../src/book.js"></script>
|
||||
<script src="../src/chapter.js"></script>
|
||||
<script src="../src/renderer.js"></script>
|
||||
<script src="../src/replace.js"></script>
|
||||
<script src="../src/epubcfi.js"></script>
|
||||
<script src="../src/render_iframe.js"></script>
|
||||
<script src="../src/layout.js"></script>
|
||||
<script src="../src/pagination.js"></script>
|
||||
|
||||
<!-- Hooks -->
|
||||
<!-- <script src="../hooks/default/transculsions.js"></script> -->
|
||||
<!-- <script src="../hooks/default/endnotes.js"></script> -->
|
||||
<script src="../hooks/default/smartimages.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
EPUBJS.filePath = "../reader/js/libs/";
|
||||
EPUBJS.cssPath = "../reader/css/";
|
||||
|
||||
</script>
|
||||
<script src="../lib/epub.js"></script>
|
||||
<script src="../lib/epubjs/core.js"></script>
|
||||
<script src="../lib/epubjs/book.js"></script>
|
||||
<script src="../lib/epubjs/parser.js"></script>
|
||||
<script src="../lib/epubjs/spine.js"></script>
|
||||
<script src="../lib/epubjs/navigation.js"></script>
|
||||
<script src="../lib/epubjs/epubcfi.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
|
||||
}
|
||||
|
||||
#main {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#area {
|
||||
#viewer {
|
||||
display: block;
|
||||
margin: 5% auto;
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
margin: 5% auto;
|
||||
max-width: 1250px;
|
||||
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
border: none;
|
||||
}
|
||||
|
||||
|
@ -102,27 +57,79 @@
|
|||
.arrow:active {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#toc {
|
||||
display: block;
|
||||
margin: 10px auto;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var book = ePub("../reader/moby-dick/", {restore: true, reload: true });
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
<select id="toc"></select>
|
||||
<!-- <iframe id="viewer"></iframe> -->
|
||||
<div id="viewer"></div>
|
||||
<div id="prev" class="arrow">‹</div>
|
||||
<div id="next" class="arrow">›</div>
|
||||
|
||||
<script>
|
||||
var $viewer = document.getElementById("viewer");
|
||||
var $next = document.getElementById("next");
|
||||
var $prev = document.getElementById("prev");
|
||||
var currentSection;
|
||||
var currentSectionIndex = 7;
|
||||
|
||||
book.renderTo("area");
|
||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
||||
book.loaded.navigation.then(function(nav){
|
||||
var toc = nav.get();
|
||||
var $select = document.getElementById("toc"),
|
||||
docfrag = document.createDocumentFragment();
|
||||
|
||||
toc.forEach(function(chapter) {
|
||||
var option = document.createElement("option");
|
||||
option.textContent = chapter.label;
|
||||
option.ref = chapter.href;
|
||||
|
||||
docfrag.appendChild(option);
|
||||
});
|
||||
|
||||
$select.appendChild(docfrag);
|
||||
|
||||
$select.onchange = function(){
|
||||
var index = $select.selectedIndex,
|
||||
url = $select.options[index].ref;
|
||||
display(url);
|
||||
return false;
|
||||
};
|
||||
|
||||
book.opened.then(function(){
|
||||
display(currentSectionIndex);
|
||||
});
|
||||
|
||||
$next.addEventListener("click", function(){
|
||||
var displayed = display(currentSectionIndex+1);
|
||||
if(displayed) currentSectionIndex++;
|
||||
}, false);
|
||||
|
||||
$prev.addEventListener("click", function(){
|
||||
var displayed = display(currentSectionIndex-1);
|
||||
if(displayed) currentSectionIndex--;
|
||||
}, false);
|
||||
|
||||
function display(item){
|
||||
var section = book.spine.get(item);
|
||||
if(section) {
|
||||
currentSection = section;
|
||||
section.render().then(function(html){
|
||||
// $viewer.srcdoc = html;
|
||||
$viewer.innerHTML = html;
|
||||
});
|
||||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#main {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
margin: 5% auto;
|
||||
max-width: 1250px;
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#prev {
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
#next {
|
||||
right: 40px;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
margin-top: -32px;
|
||||
font-size: 64px;
|
||||
color: #E2E2E2;
|
||||
font-family: arial, sans-serif;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.arrow:hover {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.arrow:active {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#loader {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
margin: -33px 0 0 -33px;
|
||||
}
|
||||
|
||||
#toc {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#main {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
margin: 5% auto;
|
||||
max-width: 1250px;
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#prev {
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
#next {
|
||||
right: 40px;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
margin-top: -32px;
|
||||
font-size: 64px;
|
||||
color: #E2E2E2;
|
||||
font-family: arial, sans-serif;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.arrow:hover {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.arrow:active {
|
||||
color: #000;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader/moby-dick/");
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.renderTo("area");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,45 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Contained ePub Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<!-- Zip JS -->
|
||||
<script src="/reader/js/libs/zip.min.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
EPUBJS.filePath = "../reader/js/libs/";
|
||||
EPUBJS.cssPath = "../reader/css/";
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader/moby-dick.epub");
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();" class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.renderTo("area");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,112 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Polymer custom-elements ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
|
||||
<script src="../libs/polymer/custom-elements.min.js"></script>
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
overflow: auto;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 480px;
|
||||
height: 640px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
margin: 50px auto;
|
||||
background: #fff;
|
||||
border-radius: 0 5px 5px 0;
|
||||
-moz-box-shadow: 0px 5px 10px rgba(0,0,0,.1);
|
||||
-webkit-box-shadow: 0px 5px 10px rgba(0,0,0,.1);
|
||||
box-shadow: 0px 5px 10px rgba(0,0,0,.1);
|
||||
}
|
||||
|
||||
epub-reader {
|
||||
border: none;
|
||||
padding: 40px 40px;
|
||||
}
|
||||
|
||||
iframe {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
|
||||
var epubPrototype = Object.create(HTMLElement.prototype);
|
||||
|
||||
epubPrototype.readyCallback = function() {
|
||||
this.create();
|
||||
this.Book.renderTo(this);
|
||||
};
|
||||
|
||||
epubPrototype.create = function() {
|
||||
var src = this.getAttribute("src"),
|
||||
width = this.getAttribute("width") || false,
|
||||
height = this.getAttribute("height") || false,
|
||||
spreads = this.getAttribute("spreads") != null ? true : false,
|
||||
restore = this.getAttribute("restore") != null ? true : false;
|
||||
|
||||
this.Book = new EPUBJS.Book({
|
||||
width: width,
|
||||
height: height,
|
||||
spreads : spreads,
|
||||
restore : restore
|
||||
});
|
||||
|
||||
this.Book.open(src);
|
||||
|
||||
};
|
||||
|
||||
epubPrototype.prevPage = function() {
|
||||
this.Book.prevPage();
|
||||
}
|
||||
|
||||
epubPrototype.nextPage = function() {
|
||||
this.Book.nextPage();
|
||||
}
|
||||
|
||||
document.register('epub-reader', {
|
||||
prototype: epubPrototype
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="wrapper">
|
||||
<epub-reader id="book" src="../reader/moby-dick/" width="400" height="600" restore></epub-reader>
|
||||
</div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book = document.getElementById("book");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,76 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
overflow: auto;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 480px;
|
||||
height: 640px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
margin: 20px auto;
|
||||
background: #fff;
|
||||
border-radius: 0 5px 5px 0;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 480px;
|
||||
height: 640px;
|
||||
margin: 0 auto;
|
||||
-moz-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
-webkit-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader/moby-dick/", {
|
||||
width: 480,
|
||||
height: 645,
|
||||
spreads : false,
|
||||
fixedLayout : true
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="wrapper">
|
||||
<div id="area"></div>
|
||||
</div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.renderTo("area").then(function(){
|
||||
Book.setStyle("padding", "0 40px");
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,229 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title></title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimal-ui">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<link rel="stylesheet" href="../reader/css/normalize.css">
|
||||
<link rel="stylesheet" href="../reader/css/main.css">
|
||||
<link rel="stylesheet" href="../reader/css/popup.css">
|
||||
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="epubjs/libs/jquery-1.9.0.min.js"><\/script>')</script>
|
||||
-->
|
||||
<script src="../libs/jquery/jquery-2.1.0.js"></script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
document.onreadystatechange = function () {
|
||||
if (document.readyState == "complete") {
|
||||
EPUBJS.VERSION = "0.1.6";
|
||||
|
||||
EPUBJS.filePath = "js/libs/";
|
||||
EPUBJS.cssPath = "../reader/css/";
|
||||
// fileStorage.filePath = EPUBJS.filePath;
|
||||
|
||||
ePubReader("../reader/moby-dick/");
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<!-- Render -->
|
||||
<script src="../reader/js/epub.min.js"></script>
|
||||
|
||||
<!-- Hooks -->
|
||||
<script src="../reader/js/hooks.min.js"></script>
|
||||
|
||||
<!-- Reader -->
|
||||
<script src="../reader/js/reader.min.js"></script>
|
||||
|
||||
<!-- Plugins -->
|
||||
<script src="../reader/plugins/search.js"></script>
|
||||
|
||||
<!-- Full Screen -->
|
||||
<script src="../reader/js/libs/screenfull.min.js"></script>
|
||||
|
||||
<!-- Highlights -->
|
||||
<script src="../reader/js/libs/jquery.highlight.js"></script>
|
||||
<script src="../hooks/extensions/highlight.js"></script>
|
||||
|
||||
<!-- Hypothes.is -->
|
||||
<!-- <script src="https://static.hypothes.is/lib/jquery-21.10.2.min.js"</script>-->
|
||||
<script src="https://static.hypothes.is/lib/jquery.scrollintoview.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.widget.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.autocomplete.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.core.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.menu.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.position.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.effect.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.effect-blind.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.effect-highlight.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jquery.ui.effect-forecolor-highlight.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/jschannel.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/gettext.min.js"></script>
|
||||
<script src="https://static.hypothes.is/locale/data.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/annotator.min.js"></script>
|
||||
<script src="https://static.hypothes.is/js/plugin/bridge.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/annotator.document.min.js"></script>
|
||||
<!-- <script src="https://static.hypothes.is/js/plugin/heatmap.js"></script> -->
|
||||
<script src="https://static.hypothes.is/lib/annotator.texthighlights.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/annotator.dtm.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/annotator.textanchors.min.js"></script>
|
||||
<script src="https://static.hypothes.is/lib/annotator.fuzzytextanchors.min.js"></script>
|
||||
<!-- <script src="https://static.hypothes.is/lib/annotator.pdf.min.js"></script> -->
|
||||
<script src="https://static.hypothes.is/js/plugin/toolbar.js"></script>
|
||||
<script src="https://static.hypothes.is/js/inject.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="https://static.hypothes.is/lib/jquery-ui-smoothness.min.css"></link>
|
||||
<link rel="stylesheet" href="https://static.hypothes.is/css/inject.css">
|
||||
|
||||
|
||||
<script async src="../hooks/extensions/hypothesis.js"></script>
|
||||
<script src="../reader_src/plugins/hypothesis.js"></script>
|
||||
|
||||
<style>
|
||||
#annotator-toolbar {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 18px;
|
||||
height: 27px;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
#annotator-toolbar .annotator-toolbar {
|
||||
position: absolute;
|
||||
top: auto;
|
||||
right: auto;
|
||||
left: auto;
|
||||
/* z-index: 100; */
|
||||
}
|
||||
|
||||
#annotator-toolbar .annotator-toolbar li {
|
||||
background: none;
|
||||
border: 0;
|
||||
box-shadow: none;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#hypothesis {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
width: 33%;
|
||||
margin: 0 .5%;
|
||||
overflow: hidden;
|
||||
z-index: 0;
|
||||
background: #4e4e4e;
|
||||
}
|
||||
|
||||
#hypothesis .annotator-frame {
|
||||
background: none;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
margin: auto !important;
|
||||
width: 100%;
|
||||
z-index: auto;
|
||||
}
|
||||
|
||||
#annotator-notice {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#main {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#main.single {
|
||||
width: 66%;
|
||||
}
|
||||
|
||||
#main.single.closed {
|
||||
-webkit-transform: translate(51.6%, 0);
|
||||
-moz-transform: translate(51.6%, 0);
|
||||
}
|
||||
|
||||
#sidebar {
|
||||
width: 34%
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="sidebar">
|
||||
<div id="panels">
|
||||
<input id="searchBox" placeholder="search" type="search">
|
||||
|
||||
<a id="show-Search" class="show_view icon-search" data-view="Search">Search</a>
|
||||
<a id="show-Toc" class="show_view icon-list-1 active" data-view="Toc">TOC</a>
|
||||
<a id="show-Bookmarks" class="show_view icon-bookmark" data-view="Bookmarks">Bookmarks</a>
|
||||
<a id="show-Notes" class="show_view icon-edit" data-view="Notes">Notes</a>
|
||||
</div>
|
||||
<div id="tocView" class="view">
|
||||
</div>
|
||||
<div id="searchView" class="view">
|
||||
<ul id="searchResults"></ul>
|
||||
</div>
|
||||
<div id="bookmarksView" class="view">
|
||||
<ul id="bookmarks"></ul>
|
||||
</div>
|
||||
<div id="notesView" class="view">
|
||||
<div id="new-note">
|
||||
<textarea id="note-text"></textarea>
|
||||
<button id="note-anchor">Anchor</button>
|
||||
</div>
|
||||
<ol id="notes"></ol>
|
||||
</div>
|
||||
</div>
|
||||
<div id="hypothesis"></div>
|
||||
<div id="main">
|
||||
|
||||
<div id="titlebar">
|
||||
<div id="opener">
|
||||
<a id="slider" class="icon-menu">Menu</a>
|
||||
</div>
|
||||
<div id="metainfo">
|
||||
<span id="book-title"></span>
|
||||
<span id="title-seperator"> – </span>
|
||||
<span id="chapter-title"></span>
|
||||
</div>
|
||||
<div id="title-controls">
|
||||
<a id="bookmark" class="icon-bookmark-empty">Bookmark</a>
|
||||
<a id="setting" class="icon-cog">Settings</a>
|
||||
<a id="fullscreen" class="icon-resize-full">Fullscreen</a>
|
||||
<div id="annotator-toolbar"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="divider"></div>
|
||||
<div id="prev" class="arrow">‹</div>
|
||||
<div id="viewer"></div>
|
||||
<div id="next" class="arrow">›</div>
|
||||
|
||||
<div id="loader"><img src="../reader/img/loader.gif"></div>
|
||||
</div>
|
||||
<div class="modal md-effect-1" id="settings-modal">
|
||||
<div class="md-content">
|
||||
<h3>Settings</h3>
|
||||
<div>
|
||||
<p>
|
||||
<!-- <input type='radio' name='fontSize' value='x-small'><span class='xsmall'>Extra Small</span><br>
|
||||
<input type='radio' name='fontSize' value='small'><span class='small'>Small</span><br>
|
||||
<input type='radio' name='fontSize' value='medium'><span class='medium'>Medium</span><br>
|
||||
<input type='radio' name='fontSize' value='large'><span class='large'>Large</span><br>
|
||||
<input type='radio' name='fontSize' value='x-large'><span class='xlarge'>Extra Large</span> -->
|
||||
<input type="checkbox" id="sidebarReflow" name="sidebarReflow">Reflow text when sidebars are open.</input>
|
||||
</p>
|
||||
</div>
|
||||
<div class="closer icon-cancel-circled"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overlay"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,98 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>ePubJS Examples</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
overflow: auto;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 480px;
|
||||
height: 640px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
margin: 28px auto;
|
||||
background: #fff;
|
||||
border-radius: 0 5px 5px 0;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 480px;
|
||||
height: 660px;
|
||||
margin: -30px auto;
|
||||
-moz-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
-webkit-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
padding: 40px 40px;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 1em;
|
||||
line-height: 1.33em;
|
||||
font-family: serif;
|
||||
|
||||
}
|
||||
h1 {
|
||||
text-align: center
|
||||
font-size: 1.5em;
|
||||
line-height: 1.33em;
|
||||
text-align: center;
|
||||
padding-bottom: 0em;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
font-weight: normal;
|
||||
letter-spacing: 4px;
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
ol {
|
||||
width: 350px;
|
||||
margin: 50px auto;
|
||||
/*font-family: sans-serif;*/
|
||||
}
|
||||
|
||||
a {
|
||||
font-size: 1.2em;
|
||||
line-height: 1.33em;
|
||||
color: #000;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="wrapper">
|
||||
<div id="area">
|
||||
|
||||
<h1>Examples</h1>
|
||||
<ol>
|
||||
<li><a href="single.html">Single</a></li>
|
||||
<li><a href="basic.html">Basic</a></li>
|
||||
<li><a href="contained.html">Contained</a></li>
|
||||
<li><a href="promises.html">Promises</a></li>
|
||||
<li><a href="fixed.html">Fixed</a></li>
|
||||
<li><a href="custom-elements.html">Custom Element</a></li>
|
||||
<li><a href="mathml.html">MathML</a></li>
|
||||
<li><a href="hypothesis.html">Annotations with Hypothes. is</a></li>
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,37 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
<script src="../hooks/default/mathml.js"></script>
|
||||
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../books/mathjax_tests/");
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.renderTo("area");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
|
@ -1,207 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<!-- EPUBJS Renderer -->
|
||||
<!-- zip -->
|
||||
<script src="../libs/zip/zip.js"></script>
|
||||
<script src="../libs/zip/zip-fs.js"></script>
|
||||
<script src="../libs/zip/zip-ext.js"></script>
|
||||
<script src="../libs/zip/inflate.js"></script>
|
||||
<script src="../libs/zip/mime-types.js"></script>
|
||||
|
||||
|
||||
<!-- Render -->
|
||||
<script src="../libs/underscore/underscore.js"></script>
|
||||
<script src="../libs/rsvp/rsvp.js"></script>
|
||||
<script src="../libs/fileStorage/fileStorage.min.js"></script>
|
||||
|
||||
<script src="../src/base.js"></script>
|
||||
<script src="../src/core.js"></script>
|
||||
<script src="../src/unarchiver.js"></script>
|
||||
<script src="../src/parser.js"></script>
|
||||
<script src="../src/hooks.js"></script>
|
||||
<script src="../src/book.js"></script>
|
||||
<script src="../src/chapter.js"></script>
|
||||
<script src="../src/renderer.js"></script>
|
||||
<script src="../src/epubcfi.js"></script>
|
||||
<script src="../src/replace.js"></script>
|
||||
<script src="../src/render_iframe.js"></script>
|
||||
<script src="../src/layout.js"></script>
|
||||
<script src="../src/pagination.js"></script>
|
||||
<!-- Hooks -->
|
||||
<!-- <script src="../hooks/default/transculsions.js"></script> -->
|
||||
<!-- <script src="../hooks/default/endnotes.js"></script> -->
|
||||
<script src="../hooks/default/smartimages.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
EPUBJS.filePath = "../reader/js/libs/";
|
||||
EPUBJS.cssPath = "../reader/css/";
|
||||
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
|
||||
}
|
||||
|
||||
#main {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* overflow: hidden; */
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
margin: 5% auto;
|
||||
max-width: 1250px;
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
border: none;
|
||||
}
|
||||
|
||||
#prev {
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
#next {
|
||||
right: 40px;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
margin-top: -32px;
|
||||
font-size: 64px;
|
||||
color: #E2E2E2;
|
||||
font-family: arial, sans-serif;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.arrow:hover {
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.arrow:active {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#controls {
|
||||
position: absolute;
|
||||
bottom: 16px;
|
||||
left: 50%;
|
||||
width: 400px;
|
||||
margin-left: -200px;
|
||||
text-align: center;
|
||||
display: none;
|
||||
}
|
||||
|
||||
#controls > input[type=range] {
|
||||
width: 400px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var book = ePub("../reader/moby-dick/", { width: 1076, height: 588 });
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="book.nextPage();"class="arrow">›</div>
|
||||
<div id="controls">
|
||||
<input id="currentpg" size="3" maxlength="3"/> / <span id="totalpg">0</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var controls = document.getElementById("controls");
|
||||
var currentPage = document.getElementById("currentpg");
|
||||
var totalPages = document.getElementById("totalpg");
|
||||
var slider = document.createElement("input");
|
||||
var pageList;
|
||||
var slide = function(){
|
||||
book.gotoPage(slider.value);
|
||||
};
|
||||
var throttledSlide = _.throttle(slide, 200);
|
||||
var mouseDown = false;
|
||||
|
||||
var rendered = book.renderTo("area");
|
||||
|
||||
// Load in stored pageList from json or local storage
|
||||
///*
|
||||
// EPUBJS.core.request("page_list.json").then(function(storedPageList){
|
||||
// pageList = storedPageList;
|
||||
// console.log(storedPageList)
|
||||
// book.loadPagination(pageList);
|
||||
// });
|
||||
|
||||
|
||||
// Or generate the pageList on the fly
|
||||
book.ready.all.then(function(){
|
||||
book.generatePagination();
|
||||
});
|
||||
|
||||
// Wait for the pageList to be ready and then show slider
|
||||
book.pageListReady.then(function(pageList){
|
||||
controls.style.display = "block";
|
||||
// console.log(JSON.stringify(pageList)); // Save the result
|
||||
slider.setAttribute("type", "range");
|
||||
slider.setAttribute("min", book.pagination.firstPage);
|
||||
slider.setAttribute("max", book.pagination.lastPage);
|
||||
slider.setAttribute("step", 1);
|
||||
slider.setAttribute("value", 0);
|
||||
|
||||
slider.addEventListener("change", throttledSlide, false);
|
||||
slider.addEventListener("mousedown", function(){
|
||||
mouseDown = true;
|
||||
}, false);
|
||||
slider.addEventListener("mouseup", function(){
|
||||
mouseDown = false;
|
||||
}, false);
|
||||
|
||||
// Wait for book to be rendered to get current page
|
||||
rendered.then(function(){
|
||||
var currentLocation = book.getCurrentLocationCfi();
|
||||
var currentPage = book.pagination.pageFromCfi(currentLocation);
|
||||
slider.value = currentPage;
|
||||
currentPage.value = currentPage;
|
||||
});
|
||||
|
||||
controls.appendChild(slider);
|
||||
|
||||
totalPages.innerText = book.pagination.totalPages;
|
||||
currentPage.addEventListener("change", function(){
|
||||
book.gotoPage(currentPage.value);
|
||||
}, false);
|
||||
});
|
||||
|
||||
book.on('book:pageChanged', function(location){
|
||||
if(!mouseDown) {
|
||||
slider.value = location.anchorPage;
|
||||
}
|
||||
currentPage.value = location.anchorPage;
|
||||
console.log(location.pageRange)
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,74 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>ePubJS Promises Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader/moby-dick/", { restore: true });
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="area"></div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
<div id="loader"><img src="../reader/img/loader.gif"></div>
|
||||
<select id="toc"></select>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.getMetadata().then(function(meta){
|
||||
|
||||
document.title = meta.bookTitle+" – "+meta.creator;
|
||||
|
||||
});
|
||||
|
||||
Book.getToc().then(function(toc){
|
||||
|
||||
var $select = document.getElementById("toc"),
|
||||
docfrag = document.createDocumentFragment();
|
||||
|
||||
toc.forEach(function(chapter) {
|
||||
var option = document.createElement("option");
|
||||
option.textContent = chapter.label;
|
||||
option.ref = chapter.href;
|
||||
|
||||
docfrag.appendChild(option);
|
||||
});
|
||||
|
||||
$select.appendChild(docfrag);
|
||||
|
||||
$select.onchange = function(){
|
||||
var index = $select.selectedIndex,
|
||||
url = $select.options[index].ref;
|
||||
|
||||
Book.goto(url);
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Book.ready.all.then(function(){
|
||||
document.getElementById("loader").style.display = "none";
|
||||
});
|
||||
|
||||
Book.renderTo("area");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,111 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title></title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<link rel="stylesheet" href="../reader/css/normalize.css">
|
||||
<link rel="stylesheet" href="../reader/css/main.css">
|
||||
<link rel="stylesheet" href="../reader/css/popup.css">
|
||||
<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="epubjs/libs/jquery-1.9.0.min.js"><\/script>')</script>
|
||||
-->
|
||||
<script src="../libs/jquery/jquery-2.1.0.js"></script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
document.onreadystatechange = function () {
|
||||
if (document.readyState == "complete") {
|
||||
EPUBJS.VERSION = "0.1.6";
|
||||
|
||||
EPUBJS.filePath = "js/libs/";
|
||||
EPUBJS.cssPath = "../reader/css/";
|
||||
// fileStorage.filePath = EPUBJS.filePath;
|
||||
|
||||
ePubReader("../reader/moby-dick/");
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<!-- Render -->
|
||||
<script src="../reader/js/epub.min.js"></script>
|
||||
|
||||
<!-- Hooks -->
|
||||
<script src="../reader/js/hooks.min.js"></script>
|
||||
|
||||
<!-- Reader -->
|
||||
<script src="../reader/js/reader.min.js"></script>
|
||||
|
||||
<!-- Plugins -->
|
||||
<script src="../reader_src/plugins/search.js"></script>
|
||||
|
||||
<!-- Full Screen -->
|
||||
<script src="../reader/js/libs/screenfull.min.js"></script>
|
||||
|
||||
<!-- Highlights -->
|
||||
<script src="../reader/js/libs/jquery.highlight.js"></script>
|
||||
<script src="../hooks/extensions/highlight.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="sidebar">
|
||||
<div id="panels">
|
||||
<input id="searchBox" placeholder="search" type="search">
|
||||
|
||||
<a id="show-Search" class="show_view icon-search" data-view="Search">Search</a>
|
||||
<a id="show-Toc" class="show_view icon-list-1 active" data-view="Toc">TOC</a>
|
||||
<a id="show-Bookmarks" class="show_view icon-bookmark" data-view="Bookmarks">Bookmarks</a>
|
||||
<a id="show-Notes" class="show_view icon-edit" data-view="Notes">Notes</a>
|
||||
|
||||
</div>
|
||||
<div id="tocView">
|
||||
</div>
|
||||
<div id="searchView">
|
||||
<ul id="searchResults"></ul>
|
||||
</div>
|
||||
<div id="bookmarksView">
|
||||
<ul id="bookmarks"></ul>
|
||||
</div>
|
||||
</div>
|
||||
<div id="main">
|
||||
|
||||
<div id="titlebar">
|
||||
<div id="opener">
|
||||
<a id="slider" class="icon-menu">Menu</a>
|
||||
</div>
|
||||
<div id="metainfo">
|
||||
<span id="book-title"></span>
|
||||
<span id="title-seperator"> – </span>
|
||||
<span id="chapter-title"></span>
|
||||
</div>
|
||||
<div id="title-controls">
|
||||
<a id="bookmark" class="icon-bookmark-empty">Bookmark</a>
|
||||
<a id="setting" class="icon-cog">Settings</a>
|
||||
<a id="fullscreen" class="icon-resize-full">Fullscreen</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="divider"></div>
|
||||
<div id="prev" class="arrow">‹</div>
|
||||
<div id="viewer"></div>
|
||||
<div id="next" class="arrow">›</div>
|
||||
|
||||
<div id="loader"><img src="../reader/img/loader.gif"></div>
|
||||
</div>
|
||||
<div class="modal md-effect-1" id="settings-modal">
|
||||
<div class="md-content">
|
||||
<h3>Settings</h3>
|
||||
<div>
|
||||
</div>
|
||||
<div class="closer icon-cancel-circled"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overlay"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,76 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Basic ePubJS Example</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
|
||||
<!-- EPUBJS Renderer -->
|
||||
<script src="../build/epub.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
overflow: auto;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 480px;
|
||||
height: 640px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
margin: 20px auto;
|
||||
background: #fff;
|
||||
border-radius: 0 5px 5px 0;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 480px;
|
||||
height: 650px;
|
||||
margin: -5px auto;
|
||||
-moz-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
-webkit-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
padding: 40px 40px;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
var Book = ePub("../reader/moby-dick/", {
|
||||
width: 400,
|
||||
height: 600,
|
||||
spreads : false
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="prev" onclick="Book.prevPage();" class="arrow">‹</div>
|
||||
<div id="wrapper">
|
||||
<div id="area"></div>
|
||||
</div>
|
||||
<div id="next" onclick="Book.nextPage();"class="arrow">›</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
Book.renderTo("area").then(function(){
|
||||
//Book.setStyle("width", "400px");
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,159 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, renderer){
|
||||
|
||||
var notes = renderer.contents.querySelectorAll('a[href]'),
|
||||
items = Array.prototype.slice.call(notes), //[].slice.call()
|
||||
attr = "epub:type",
|
||||
type = "noteref",
|
||||
folder = EPUBJS.core.folder(location.pathname),
|
||||
cssPath = (folder + EPUBJS.cssPath) || folder,
|
||||
popups = {};
|
||||
|
||||
EPUBJS.core.addCss(cssPath + "popup.css", false, renderer.render.document.head);
|
||||
|
||||
|
||||
items.forEach(function(item){
|
||||
var epubType = item.getAttribute(attr),
|
||||
href,
|
||||
id,
|
||||
el,
|
||||
pop,
|
||||
pos,
|
||||
left,
|
||||
top,
|
||||
txt;
|
||||
|
||||
if(epubType != type) return;
|
||||
|
||||
href = item.getAttribute("href");
|
||||
id = href.replace("#", '');
|
||||
el = renderer.render.document.getElementById(id);
|
||||
|
||||
|
||||
item.addEventListener("mouseover", showPop, false);
|
||||
item.addEventListener("mouseout", hidePop, false);
|
||||
|
||||
function showPop(){
|
||||
var poppos,
|
||||
iheight = renderer.height,
|
||||
iwidth = renderer.width,
|
||||
tip,
|
||||
pop,
|
||||
maxHeight = 225,
|
||||
itemRect;
|
||||
|
||||
if(!txt) {
|
||||
pop = el.cloneNode(true);
|
||||
txt = pop.querySelector("p");
|
||||
}
|
||||
|
||||
// chapter.replaceLinks.bind(this) //TODO:Fred - update?
|
||||
//-- create a popup with endnote inside of it
|
||||
if(!popups[id]) {
|
||||
popups[id] = document.createElement("div");
|
||||
popups[id].setAttribute("class", "popup");
|
||||
|
||||
pop_content = document.createElement("div");
|
||||
|
||||
popups[id].appendChild(pop_content);
|
||||
|
||||
pop_content.appendChild(txt);
|
||||
pop_content.setAttribute("class", "pop_content");
|
||||
|
||||
renderer.render.document.body.appendChild(popups[id]);
|
||||
|
||||
//-- TODO: will these leak memory? - Fred
|
||||
popups[id].addEventListener("mouseover", onPop, false);
|
||||
popups[id].addEventListener("mouseout", offPop, false);
|
||||
|
||||
//-- Add hide on page change
|
||||
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", hidePop);
|
||||
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", offPop);
|
||||
renderer.on("renderer:pageChanged", hidePop, this);
|
||||
renderer.on("renderer:pageChanged", offPop, this);
|
||||
// chapter.book.on("renderer:chapterDestroy", hidePop, this);
|
||||
}
|
||||
|
||||
pop = popups[id];
|
||||
|
||||
|
||||
//-- get location of item
|
||||
itemRect = item.getBoundingClientRect();
|
||||
left = itemRect.left;
|
||||
top = itemRect.top;
|
||||
|
||||
//-- show the popup
|
||||
pop.classList.add("show");
|
||||
|
||||
//-- locations of popup
|
||||
popRect = pop.getBoundingClientRect();
|
||||
|
||||
//-- position the popup
|
||||
pop.style.left = left - popRect.width / 2 + "px";
|
||||
pop.style.top = top + "px";
|
||||
|
||||
|
||||
//-- Adjust max height
|
||||
if(maxHeight > iheight / 2.5) {
|
||||
maxHeight = iheight / 2.5;
|
||||
pop_content.style.maxHeight = maxHeight + "px";
|
||||
}
|
||||
|
||||
//-- switch above / below
|
||||
if(popRect.height + top >= iheight - 25) {
|
||||
pop.style.top = top - popRect.height + "px";
|
||||
pop.classList.add("above");
|
||||
}else{
|
||||
pop.classList.remove("above");
|
||||
}
|
||||
|
||||
//-- switch left
|
||||
if(left - popRect.width <= 0) {
|
||||
pop.style.left = left + "px";
|
||||
pop.classList.add("left");
|
||||
}else{
|
||||
pop.classList.remove("left");
|
||||
}
|
||||
|
||||
//-- switch right
|
||||
if(left + popRect.width / 2 >= iwidth) {
|
||||
//-- TEMP MOVE: 300
|
||||
pop.style.left = left - 300 + "px";
|
||||
|
||||
popRect = pop.getBoundingClientRect();
|
||||
pop.style.left = left - popRect.width + "px";
|
||||
//-- switch above / below again
|
||||
if(popRect.height + top >= iheight - 25) {
|
||||
pop.style.top = top - popRect.height + "px";
|
||||
pop.classList.add("above");
|
||||
}else{
|
||||
pop.classList.remove("above");
|
||||
}
|
||||
|
||||
pop.classList.add("right");
|
||||
}else{
|
||||
pop.classList.remove("right");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function onPop(){
|
||||
popups[id].classList.add("on");
|
||||
}
|
||||
|
||||
function offPop(){
|
||||
popups[id].classList.remove("on");
|
||||
}
|
||||
|
||||
function hidePop(){
|
||||
setTimeout(function(){
|
||||
popups[id].classList.remove("show");
|
||||
}, 100);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").mathml = function(callback, renderer){
|
||||
|
||||
// check of currentChapter properties contains 'mathml'
|
||||
if(renderer.currentChapter.manifestProperties.indexOf("mathml") !== -1 ){
|
||||
|
||||
// Assign callback to be inside iframe window
|
||||
renderer.iframe.contentWindow.mathmlCallback = callback;
|
||||
|
||||
// add MathJax config script tag to the renderer body
|
||||
var s = document.createElement("script");
|
||||
s.type = 'text/x-mathjax-config';
|
||||
s.innerHTML = '\
|
||||
MathJax.Hub.Register.StartupHook("End",function () { \
|
||||
window.mathmlCallback(); \
|
||||
});\
|
||||
MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); \
|
||||
';
|
||||
renderer.doc.body.appendChild(s);
|
||||
// add MathJax.js to renderer head
|
||||
EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML", null, renderer.doc.head);
|
||||
|
||||
} else {
|
||||
if(callback) callback();
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, renderer){
|
||||
var images = renderer.contents.querySelectorAll('img'),
|
||||
items = Array.prototype.slice.call(images),
|
||||
iheight = renderer.height,//chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
|
||||
oheight;
|
||||
|
||||
if(renderer.layoutSettings.layout != "reflowable") {
|
||||
callback();
|
||||
return; //-- Only adjust images for reflowable text
|
||||
}
|
||||
|
||||
items.forEach(function(item){
|
||||
|
||||
function size() {
|
||||
var itemRect = item.getBoundingClientRect(),
|
||||
rectHeight = itemRect.height,
|
||||
top = itemRect.top,
|
||||
oHeight = item.getAttribute('data-height'),
|
||||
height = oHeight || rectHeight,
|
||||
newHeight,
|
||||
fontSize = Number(getComputedStyle(item, "").fontSize.match(/(\d*(\.\d*)?)px/)[1]),
|
||||
fontAdjust = fontSize ? fontSize / 2 : 0;
|
||||
|
||||
iheight = renderer.contents.clientHeight;
|
||||
if(top < 0) top = 0;
|
||||
|
||||
if(height + top >= iheight) {
|
||||
|
||||
if(top < iheight/2) {
|
||||
// Remove top and half font-size from height to keep container from overflowing
|
||||
newHeight = iheight - top - fontAdjust;
|
||||
item.style.maxHeight = newHeight + "px";
|
||||
item.style.width= "auto";
|
||||
}else{
|
||||
if(height > iheight) {
|
||||
item.style.maxHeight = iheight + "px";
|
||||
item.style.width= "auto";
|
||||
itemRect = item.getBoundingClientRect();
|
||||
height = itemRect.height;
|
||||
}
|
||||
item.style.display = "block";
|
||||
item.style["WebkitColumnBreakBefore"] = "always";
|
||||
item.style["breakBefore"] = "column";
|
||||
|
||||
}
|
||||
|
||||
item.setAttribute('data-height', newHeight);
|
||||
|
||||
}else{
|
||||
item.style.removeProperty('max-height');
|
||||
item.style.removeProperty('margin-top');
|
||||
}
|
||||
}
|
||||
|
||||
item.addEventListener('load', size, false);
|
||||
|
||||
renderer.on("renderer:resized", size);
|
||||
|
||||
renderer.on("renderer:chapterUnloaded", function(){
|
||||
item.removeEventListener('load', size);
|
||||
renderer.off("renderer:resized", size);
|
||||
});
|
||||
|
||||
size();
|
||||
|
||||
});
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").transculsions = function(callback, renderer){
|
||||
/*
|
||||
<aside ref="http://www.youtube.com/embed/DUL6MBVKVLI?html5=1" transclusion="video" width="560" height="315">
|
||||
<a href="http://www.youtube.com/embed/DUL6MBVKVLI"> Watch the National Geographic: The Last Roll of Kodachrome</a>
|
||||
</aside>
|
||||
*/
|
||||
|
||||
var trans = renderer.contents.querySelectorAll('[transclusion]'),
|
||||
items = Array.prototype.slice.call(trans);
|
||||
|
||||
items.forEach(function(item){
|
||||
var src = item.getAttribute("ref"),
|
||||
iframe = document.createElement('iframe'),
|
||||
orginal_width = item.getAttribute("width"),
|
||||
orginal_height = item.getAttribute("height"),
|
||||
parent = item.parentNode,
|
||||
width = orginal_width,
|
||||
height = orginal_height,
|
||||
ratio;
|
||||
|
||||
|
||||
function size() {
|
||||
width = orginal_width;
|
||||
height = orginal_height;
|
||||
|
||||
if(width > chapter.colWidth){
|
||||
ratio = chapter.colWidth / width;
|
||||
|
||||
width = chapter.colWidth;
|
||||
height = height * ratio;
|
||||
}
|
||||
|
||||
iframe.width = width;
|
||||
iframe.height = height;
|
||||
}
|
||||
|
||||
|
||||
size();
|
||||
|
||||
//-- resize event
|
||||
|
||||
|
||||
renderer.listenUntil("renderer:resized", "renderer:chapterUnloaded", size);
|
||||
|
||||
iframe.src = src;
|
||||
|
||||
//<iframe width="560" height="315" src="http://www.youtube.com/embed/DUL6MBVKVLI" frameborder="0" allowfullscreen="true"></iframe>
|
||||
parent.replaceChild(iframe, item);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").annotate = function(callback, chapter){
|
||||
|
||||
|
||||
var chap = chapter.bodyEl,
|
||||
server = 'http://127.0.0.1:5000/';
|
||||
files = [
|
||||
EPUBJS.filePath + "libs/jquery-1.9.0.js",
|
||||
EPUBJS.filePath + "libs/jquery-migrate-1.1.1.js",
|
||||
EPUBJS.filePath + "libs/annotator-full.js"
|
||||
];
|
||||
|
||||
|
||||
//EPUBJS.core.loadScripts(files, annotate, chapter.doc.head);
|
||||
// $(chapter.doc.body).annotator().annotator('setupPlugins', {}, {
|
||||
|
||||
// Filter:false,
|
||||
// Store: {
|
||||
// annotationData: {
|
||||
// 'uri': chapter.path
|
||||
// },
|
||||
// loadFromSearch: {
|
||||
// 'limit': 100,
|
||||
// 'uri': chapter.path
|
||||
// }
|
||||
// }
|
||||
|
||||
// });
|
||||
Util.mousePosition = function(e, offsetEl) {
|
||||
var offset;
|
||||
offset = $(offsetEl).position();
|
||||
return {
|
||||
top: e.pageY,
|
||||
left: e.pageX
|
||||
};
|
||||
};
|
||||
|
||||
devAnnotator = new Annotator(chapter.doc.body)
|
||||
.addPlugin('Auth', {
|
||||
tokenUrl: 'http://annotateit.org/api/token',//'http://localhost:5001/api/token'
|
||||
})
|
||||
.addPlugin('Unsupported')
|
||||
.addPlugin('AnnotateItPermissions')
|
||||
.addPlugin('Store', {
|
||||
prefix: 'http://annotateit.org/api',//'http://localhost:5000',
|
||||
loadFromSearch: {
|
||||
uri: chapter.currentChapter.href
|
||||
},
|
||||
annotationData: {
|
||||
uri: chapter.currentChapter.href
|
||||
}
|
||||
});
|
||||
|
||||
// devAnnotator.plugins.Auth.withToken(function (tok) {
|
||||
// console.log(tok);
|
||||
// })
|
||||
|
||||
EPUBJS.core.addCss("../libs/annotator/css/annotator.css", false, chapter.doc.head);
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
function annotate(){
|
||||
EPUBJS.core.addCss("css/annotator.css", false, chapter.doc.head);
|
||||
|
||||
var s = document.createElement("script");
|
||||
s.type = 'text/javascript';
|
||||
|
||||
var a = "jQuery.migrateTrace = false;";
|
||||
//a += "console.log(document.getElementById('c001p0002').getBoundingClientRect());";
|
||||
|
||||
a += "var content = $('body').annotator().annotator('setupPlugins', {}, {Filter:false});";
|
||||
|
||||
//-- Use Local Server:
|
||||
|
||||
// a += "var content = $('body').annotator(),";
|
||||
// a += " server = '" + server + "';";
|
||||
// a += " path = '" + chapter.path + "';";
|
||||
//
|
||||
// a += " content.annotator('addPlugin', 'Store', {";
|
||||
// // The endpoint of the store on your server.
|
||||
// a += " prefix: server,";
|
||||
//
|
||||
// // Attach the uri of the current page to all annotations to allow search.
|
||||
// a += " annotationData: {";
|
||||
// a += " 'uri': path";
|
||||
// a += " }";
|
||||
|
||||
// This will perform a search action rather than read when the plugin
|
||||
// loads. Will request the last 20 annotations for the current url.
|
||||
// eg. /store/endpoint/search?limit=20&uri=http://this/document/only
|
||||
// a += ","
|
||||
// a += " loadFromSearch: {";
|
||||
// a += " 'limit': 20,";
|
||||
// a += " 'uri': path";
|
||||
// a += " }";
|
||||
//a += "});";
|
||||
|
||||
s.innerHTML = a;
|
||||
|
||||
chapter.doc.body.appendChild(s);
|
||||
|
||||
if(callback) callback();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").example = function(callback, chapter){
|
||||
|
||||
|
||||
var s = document.createElement("script");
|
||||
s.type = 'text/javascript';
|
||||
s.src ="https://test.hypothes.is/app/embed.js"
|
||||
|
||||
chapter.doc.body.appendChild(s);
|
||||
|
||||
//-- Continue to other hooks
|
||||
if(callback) callback();}
|
|
@ -1,43 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").example = function(callback, chapter){
|
||||
|
||||
EPUBJS.core.addCss("css/annotator.css", false, chapter.doc.head);
|
||||
|
||||
EPUBJS.core.addScript(EPUBJS.filePath + "libs/annotator-full.js", function() {
|
||||
|
||||
//-- Config script
|
||||
var s = document.createElement("script");
|
||||
s.type = 'text/javascript';
|
||||
|
||||
a = '/* -*- js -*- */
|
||||
/*{literal}<![CDATA[*/
|
||||
/*yepnope1.5.x|WTEPUBJSL*/
|
||||
(function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f<d;f++)g=a[f].split("="),(e=z[g.shift()])&&(c=e(c,g));for(f=0;f<b;f++)c=x[f](c);return c}function g(a,e,f,g,h){var i=b(a),j=i.autoCallback;i.url.split(".").pop().split("?").shift(),i.bypass||(e&&(e=d(e)?e:e[a]||e[g]||e[a.split("/").pop().split("?")[0]]),i.instead?i.instead(a,e,f,g,h):(y[i.url]?i.noexec=!0:y[i.url]=1,f.load(i.url,i.forceCSS||!i.forceJS&&"css"==i.url.split(".").pop().split("?").shift()?"c":c,i.noexec,i.attrs,i.timeout),(d(e)||d(j))&&f.load(function(){k(),e&&e(i.origUrl,h,g),j&&j(i.origUrl,h,g),y[i.url]=2})))}function h(a,b){function c(a,c){if(a){if(e(a))c||(j=function(){var a=[].slice.call(arguments);k.apply(this,a),l()}),g(a,j,b,0,h);else if(Object(a)===a)for(n in m=function(){var b=0,c;for(c in a)a.hasOwnProperty(c)&&b++;return b}(),a)a.hasOwnProperty(n)&&(!c&&!--m&&(d(j)?j=function(){var a=[].slice.call(arguments);k.apply(this,a),l()}:j[n]=function(a){return function(){var b=[].slice.call(arguments);a&&a.apply(this,b),l()}}(k[n])),g(a[n],j,b,n,h))}else!c&&l()}var h=!!a.test,i=a.load||a.both,j=a.callback||f,k=j,l=a.complete||f,m,n;c(h?a.yep:a.nope,!!i),i&&c(i)}var i,j,l=this.yepnope.loader;if(e(a))g(a,0,l,0);else if(w(a))for(i=0;i<a.length;i++)j=a[i],e(j)?g(j,0,l,0):w(j)?B(j):Object(j)===j&&h(j,l);else Object(a)===a&&h(a,l)},B.addPrefix=function(a,b){z[a]=b},B.addFilter=function(a){x.push(a)},B.errorTimeout=1e4,null==b.readyState&&b.addEventListener&&(b.readyState="loading",b.addEventListener("DOMContentLoaded",A=function(){b.removeEventListener("DOMContentLoaded",A,0),b.readyState="complete"},0)),a.yepnope=k(),a.yepnope.executeStack=h,a.yepnope.injectJs=function(a,c,d,e,i,j){var k=b.createElement("script"),l,o,e=e||B.errorTimeout;k.src=a;for(o in d)k.setAttribute(o,d[o]);c=j?h:c||f,k.onreadystatechange=k.onload=function(){!l&&g(k.readyState)&&(l=1,c(),k.onload=k.onreadystatechange=null)},m(function(){l||(l=1,c(1))},e),i?k.onload():n.parentNode.insertBefore(k,n)},a.yepnope.injectCss=function(a,c,d,e,g,i){var e=b.createElement("link"),j,c=i?h:c||f;e.href=a,e.rel="stylesheet",e.type="text/css";for(j in d)e.setAttribute(j,d[j]);g||(n.parentNode.insertBefore(e,n),m(c,0))}})(this,document);
|
||||
yepnope([
|
||||
{
|
||||
test: window.annotator,
|
||||
nope: Array.prototype.concat.call(["https://test.hypothes.is/assets/lib/jquery-1.8.3.min.js?f38b3719", "https://test.hypothes.is/assets/lib/jschannel.min.js?a3050e46", "https://test.hypothes.is/assets/lib/annotator.min.js?c383f214", "https://test.hypothes.is/assets/js/plugin/bridge.js?0be67f72", "https://test.hypothes.is/assets/lib/dom_text.min.js?83381202", "https://test.hypothes.is/assets/js/host.min.js?b382f10e", "https://test.hypothes.is/assets/css/inject.css?ff831c08"]),
|
||||
complete: function () {
|
||||
window.annotator = new Annotator.Host(document.body, {
|
||||
/* @@ reflect routes with crossroads.js?? */
|
||||
app: "https://test.hypothes.is/app/",
|
||||
});
|
||||
window.Annotator.noConflict().$.noConflict(true);
|
||||
}
|
||||
},
|
||||
{
|
||||
test: window.requestAnimationFrame,
|
||||
nope: ["https://test.hypothes.is/assets/lib/polyfills/raf.js.min?6d9ee12a"],
|
||||
}
|
||||
]);'
|
||||
|
||||
s.innerHTML = a;
|
||||
chapter.doc.body.appendChild(s);
|
||||
|
||||
//-- Continue to other hooks
|
||||
if(callback) callback();
|
||||
|
||||
}, chapter.doc.head);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").highlight = function(callback, renderer){
|
||||
|
||||
// EPUBJS.core.addScript("js/libs/jquery.highlight.js", null, renderer.doc.head);
|
||||
|
||||
var s = document.createElement("style");
|
||||
s.innerHTML =".highlight { background: yellow; font-weight: normal; }";
|
||||
|
||||
renderer.render.document.head.appendChild(s);
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// EPUBJS.Hooks.register("beforeChapterDisplay").hypothesis = function(callback, chapter){
|
||||
//
|
||||
//
|
||||
// EPUBJS.core.addScript("https://hypothes.is/app/embed.js", null, chapter.doc.head);
|
||||
//
|
||||
// if(callback) callback();
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").hypothesis = function(callback, renderer){
|
||||
var folder = EPUBJS.core.folder(location.pathname);
|
||||
var cssPath = (folder + EPUBJS.cssPath) || folder;
|
||||
|
||||
if(!renderer) return;
|
||||
|
||||
EPUBJS.core.addScript("https://hypothes.is/app/embed.js?role=guest&light=true", null, renderer.doc.head);
|
||||
|
||||
EPUBJS.core.addCss( cssPath + "annotations.css", null, renderer.doc.head);
|
||||
|
||||
if(callback) callback();
|
||||
};
|
|
@ -1,68 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").music = function(callback, chapter){
|
||||
|
||||
var trans = chapter.doc.querySelectorAll('audio'),
|
||||
items = Array.prototype.slice.call(trans),
|
||||
playing = false;
|
||||
|
||||
items.forEach(function(item){
|
||||
var onSpread = 0;
|
||||
|
||||
|
||||
function getPage() {
|
||||
left = item.getBoundingClientRect().left;
|
||||
onSpread = Math.floor(left / chapter.spreadWidth) + 1; //-- pages start at 1
|
||||
//console.log("left", left, onPage)
|
||||
// width = orginal_width;
|
||||
// height = orginal_height;
|
||||
//
|
||||
// if(width > chapter.colWidth){
|
||||
// ratio = chapter.colWidth / width;
|
||||
//
|
||||
// width = chapter.colWidth;
|
||||
// height = height * ratio;
|
||||
// }
|
||||
//
|
||||
// iframe.width = width;
|
||||
// iframe.height = height;
|
||||
}
|
||||
|
||||
function shouldPlay(e) {
|
||||
page = 1;
|
||||
if(e) page = e.msg;
|
||||
|
||||
if(page != onSpread) return;
|
||||
|
||||
if(playing) playing.pause();
|
||||
|
||||
item.play();
|
||||
|
||||
playing = item;
|
||||
|
||||
console.log("start", item.src)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-- resize event
|
||||
|
||||
|
||||
chapter.book.listenUntil("book:resized", "book:chapterDestroy", getPage);
|
||||
|
||||
chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", shouldPlay);
|
||||
|
||||
item.removeAttribute("controls");
|
||||
|
||||
getPage();
|
||||
shouldPlay();
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
if(callback) callback();
|
||||
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
EPUBJS.Hooks.register("beforeChapterDisplay").pageTurns = function(callback, renderer){
|
||||
|
||||
var lock = false;
|
||||
var arrowKeys = function(e){
|
||||
if(lock) return;
|
||||
|
||||
if (e.keyCode == 37) {
|
||||
renderer.book.prevPage();
|
||||
lock = true;
|
||||
setTimeout(function(){
|
||||
lock = false;
|
||||
}, 100);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e.keyCode == 39) {
|
||||
renderer.book.nextPage();
|
||||
lock = true;
|
||||
setTimeout(function(){
|
||||
lock = false;
|
||||
}, 100);
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
renderer.docEl.addEventListener('keydown', arrowKeys, false);
|
||||
if(callback) callback();
|
||||
}
|
99
index.html
99
index.html
|
@ -1,99 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>ePubJS Examples</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body {
|
||||
overflow: auto;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 480px;
|
||||
height: 640px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
margin: 28px auto;
|
||||
background: #fff;
|
||||
border-radius: 0 5px 5px 0;
|
||||
}
|
||||
|
||||
#area {
|
||||
width: 480px;
|
||||
height: 660px;
|
||||
margin: -30px auto;
|
||||
-moz-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
-webkit-box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
box-shadow: inset 10px 0 20px rgba(0,0,0,.1);
|
||||
}
|
||||
|
||||
#area iframe {
|
||||
padding: 40px 40px;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 1em;
|
||||
line-height: 1.33em;
|
||||
font-family: serif;
|
||||
|
||||
}
|
||||
h1 {
|
||||
text-align: center
|
||||
font-size: 1.5em;
|
||||
line-height: 1.33em;
|
||||
text-align: center;
|
||||
padding-bottom: 0em;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
font-weight: normal;
|
||||
letter-spacing: 4px;
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
ol {
|
||||
width: 350px;
|
||||
margin: 50px auto;
|
||||
/*font-family: sans-serif;*/
|
||||
}
|
||||
|
||||
a {
|
||||
font-size: 1.2em;
|
||||
line-height: 1.33em;
|
||||
color: #000;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div id="wrapper">
|
||||
<div id="area">
|
||||
|
||||
<h1>EPUB.js<br>Examples</h1>
|
||||
<ol>
|
||||
<li><a href="examples/single.html">Single</a></li>
|
||||
<li><a href="examples/basic.html">Basic</a></li>
|
||||
<li><a href="examples/contained.html">Contained</a></li>
|
||||
<li><a href="examples/promises.html">Promises</a></li>
|
||||
<li><a href="examples/fixed.html">Fixed</a></li>
|
||||
<li><a href="examples/custom-elements.html">Custom Element</a></li>
|
||||
<li><a href="examples/mathml.html">MathML</a></li>
|
||||
<li><a href="examples/hypothesis.html">Annotations with Hypothes.is</a></li>
|
||||
<li><a href="examples/pagination.html">Pagination</a></li>
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
32
lib/epub.js
Normal file
32
lib/epub.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
if (typeof EPUBJS === 'undefined') {
|
||||
(typeof window !== 'undefined' ? window : this).EPUBJS = {};
|
||||
}
|
||||
|
||||
EPUBJS.VERSION = "0.3.0";
|
||||
|
||||
|
||||
(function(root) {
|
||||
"use strict";
|
||||
var ePub = function(_url) {
|
||||
return new EPUBJS.Book(_url);
|
||||
};
|
||||
|
||||
ePub.Render = {
|
||||
register: function(name, renderer) {
|
||||
ePub.Render[name] = renderer;
|
||||
}
|
||||
}
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === "object") {
|
||||
root.RSVP = require("rsvp");
|
||||
module.exports = ePub;
|
||||
// RequireJS
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
define(ePub);
|
||||
// Global
|
||||
} else {
|
||||
root.ePub = ePub;
|
||||
}
|
||||
|
||||
})(this);
|
178
lib/epubjs/book.js
Normal file
178
lib/epubjs/book.js
Normal file
|
@ -0,0 +1,178 @@
|
|||
EPUBJS.Book = function(_url){
|
||||
// Promises
|
||||
this.opening = new RSVP.defer();
|
||||
this.opened = this.opening.promise;
|
||||
|
||||
this.baseUrl = undefined;
|
||||
|
||||
this.spine = undefined;
|
||||
|
||||
this.loading = {
|
||||
manifest: new RSVP.defer(),
|
||||
spine: new RSVP.defer(),
|
||||
metadata: new RSVP.defer(),
|
||||
cover: new RSVP.defer(),
|
||||
navigation: new RSVP.defer(),
|
||||
pageList: new RSVP.defer()
|
||||
};
|
||||
|
||||
this.loaded = {
|
||||
manifest: this.loading.manifest.promise,
|
||||
spine: this.loading.spine.promise,
|
||||
metadata: this.loading.metadata.promise,
|
||||
cover: this.loading.cover.promise,
|
||||
navigation: this.loading.navigation.promise,
|
||||
pageList: this.loading.pageList.promise
|
||||
};
|
||||
|
||||
this.loaders = [];
|
||||
for(var promise in this.loaded){
|
||||
this.loaders.push(this.loaded[promise]);
|
||||
}
|
||||
|
||||
this.ready = RSVP.all(this.loaders);
|
||||
|
||||
// this.pageList = [];
|
||||
|
||||
|
||||
// this.ready.all.then(this._ready.bind(this));
|
||||
|
||||
if(_url) {
|
||||
this.open(_url);
|
||||
}
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.open = function(_url){
|
||||
var uri;
|
||||
var parse = new EPUBJS.Parser();
|
||||
var epubPackage;
|
||||
var book = this;
|
||||
var containerPath = "META-INF/container.xml";
|
||||
|
||||
// Reuse parsed url or create a new uri object
|
||||
if(typeof(_url) === "object") {
|
||||
uri = _url;
|
||||
} else {
|
||||
uri = EPUBJS.core.uri(_url);
|
||||
}
|
||||
|
||||
// Find path to the Container
|
||||
if(uri.extension === "opf") {
|
||||
// Direct link to package, no container
|
||||
this.packageUrl = uri.path;
|
||||
this.containerUrl = '';
|
||||
this.url = uri.directory;
|
||||
|
||||
epubPackage = this.request(this.packageUrl);
|
||||
|
||||
} else if(uri.extension === "epub" || uri.extension === "zip" ) {
|
||||
// Book is archived
|
||||
this.archived = true;
|
||||
this.url = '';
|
||||
}
|
||||
|
||||
// Find the path to the Package from the container
|
||||
else if (!uri.extension) {
|
||||
|
||||
this.containerUrl = _url + containerPath;
|
||||
|
||||
epubPackage = this.request(this.containerUrl).
|
||||
then(function(containerXml){
|
||||
return parse.container(containerXml); // Container has path to content
|
||||
}).
|
||||
then(function(paths){
|
||||
var packageUri = EPUBJS.core.uri(paths.packagePath);
|
||||
book.packageUrl = _url + paths.packagePath;
|
||||
book.url = _url + packageUri.directory; // Set Url relative to the content
|
||||
book.encoding = paths.encoding;
|
||||
|
||||
return book.request(book.packageUrl);
|
||||
}).catch(function(error) {
|
||||
// handle errors in either of the two requests
|
||||
console.error("Could not load book at: " + (this.packageUrl || this.containerPath));
|
||||
book.trigger("book:loadFailed", (this.packageUrl || this.containerPath));
|
||||
book.opening.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
epubPackage.then(function(packageXml) {
|
||||
// Get package information from epub opf
|
||||
book.unpack(packageXml);
|
||||
|
||||
// Resolve promises
|
||||
book.loading.manifest.resolve(book.package.manifest);
|
||||
book.loading.metadata.resolve(book.package.metadata);
|
||||
book.loading.spine.resolve(book.spine);
|
||||
book.loading.cover.resolve(book.cover);
|
||||
|
||||
// Resolve book opened promise
|
||||
book.opening.resolve(book);
|
||||
|
||||
// Clear queue of any waiting book request
|
||||
|
||||
}).catch(function(error) {
|
||||
// handle errors in parsing the book
|
||||
console.error(error.message, error.stack);
|
||||
book.opening.reject(error);
|
||||
});
|
||||
|
||||
return this.opened;
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.unpack = function(packageXml){
|
||||
var book = this,
|
||||
parse = new EPUBJS.Parser();
|
||||
|
||||
book.package = parse.packageContents(packageXml); // Extract info from contents
|
||||
book.package.baseUrl = book.url; // Provides a url base for resolving paths
|
||||
|
||||
book.spine = new EPUBJS.Spine(book.package, this.request);
|
||||
|
||||
book.navigation = new EPUBJS.Navigation(book.package, this.request);
|
||||
book.navigation.load().then(function(toc){
|
||||
book.toc = toc;
|
||||
book.loading.navigation.resolve(book.navigation);
|
||||
});
|
||||
|
||||
// //-- Set Global Layout setting based on metadata
|
||||
// MOVE TO RENDER
|
||||
// book.globalLayoutProperties = book.parseLayoutProperties(book.package.metadata);
|
||||
|
||||
book.cover = book.url + book.package.coverPath;
|
||||
};
|
||||
|
||||
// Alias for book.spine.get
|
||||
EPUBJS.Book.prototype.section = function(target) {
|
||||
return this.spine.get(target);
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.request = function(_url) {
|
||||
// Switch request methods
|
||||
if(this.archived) {
|
||||
// TODO: handle archived
|
||||
} else {
|
||||
return EPUBJS.core.request(_url, 'xml', this.credentials);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.setCredentials = function(_credentials) {
|
||||
this.credentials = _credentials;
|
||||
};
|
||||
|
||||
//-- Enable binding events to book
|
||||
RSVP.EventTarget.mixin(EPUBJS.Book.prototype);
|
||||
|
||||
//-- Handle RSVP Errors
|
||||
RSVP.on('error', function(event) {
|
||||
//console.error(event, event.detail);
|
||||
});
|
||||
|
||||
RSVP.configure('instrument', true); //-- true | will logging out all RSVP rejections
|
||||
// RSVP.on('created', listener);
|
||||
// RSVP.on('chained', listener);
|
||||
// RSVP.on('fulfilled', listener);
|
||||
RSVP.on('rejected', function(event){
|
||||
console.error(event.detail.message, event.detail.stack);
|
||||
});
|
156
lib/epubjs/core.js
Normal file
156
lib/epubjs/core.js
Normal file
|
@ -0,0 +1,156 @@
|
|||
EPUBJS.core = {};
|
||||
|
||||
EPUBJS.core.request = function(url, type, withCredentials) {
|
||||
var supportsURL = window.URL;
|
||||
var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer";
|
||||
|
||||
var deferred = new RSVP.defer();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
//-- Check from PDF.js:
|
||||
// https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js
|
||||
var xhrPrototype = XMLHttpRequest.prototype;
|
||||
|
||||
if (!('overrideMimeType' in xhrPrototype)) {
|
||||
// IE10 might have response, but not overrideMimeType
|
||||
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
|
||||
value: function xmlHttpRequestOverrideMimeType(mimeType) {}
|
||||
});
|
||||
}
|
||||
if(withCredentials) {
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onreadystatechange = handler;
|
||||
|
||||
if(type == 'blob'){
|
||||
xhr.responseType = BLOB_RESPONSE;
|
||||
}
|
||||
|
||||
if(type == "json") {
|
||||
xhr.setRequestHeader("Accept", "application/json");
|
||||
}
|
||||
|
||||
if(type == 'xml') {
|
||||
xhr.overrideMimeType('text/xml');
|
||||
}
|
||||
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200 || this.responseXML ) { //-- Firefox is reporting 0 for blob urls
|
||||
var r;
|
||||
|
||||
if(type == 'xml'){
|
||||
r = this.responseXML;
|
||||
}else
|
||||
if(type == 'json'){
|
||||
r = JSON.parse(this.response);
|
||||
}else
|
||||
if(type == 'blob'){
|
||||
|
||||
if(supportsURL) {
|
||||
r = this.response;
|
||||
} else {
|
||||
//-- Safari doesn't support responseType blob, so create a blob from arraybuffer
|
||||
r = new Blob([this.response]);
|
||||
}
|
||||
|
||||
}else{
|
||||
r = this.response;
|
||||
}
|
||||
|
||||
deferred.resolve(r);
|
||||
} else {
|
||||
deferred.reject({
|
||||
message : this.response,
|
||||
stack : new Error().stack
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
//-- Parse the different parts of a url, returning a object
|
||||
EPUBJS.core.uri = function(url){
|
||||
var uri = {
|
||||
protocol : '',
|
||||
host : '',
|
||||
path : '',
|
||||
origin : '',
|
||||
directory : '',
|
||||
base : '',
|
||||
filename : '',
|
||||
extension : '',
|
||||
fragment : '',
|
||||
href : url
|
||||
},
|
||||
doubleSlash = url.indexOf('://'),
|
||||
search = url.indexOf('?'),
|
||||
fragment = url.indexOf("#"),
|
||||
withoutProtocol,
|
||||
dot,
|
||||
firstSlash;
|
||||
|
||||
if(fragment != -1) {
|
||||
uri.fragment = url.slice(fragment + 1);
|
||||
url = url.slice(0, fragment);
|
||||
}
|
||||
|
||||
if(search != -1) {
|
||||
uri.search = url.slice(search + 1);
|
||||
url = url.slice(0, search);
|
||||
href = url;
|
||||
}
|
||||
|
||||
if(doubleSlash != -1) {
|
||||
uri.protocol = url.slice(0, doubleSlash);
|
||||
withoutProtocol = url.slice(doubleSlash+3);
|
||||
firstSlash = withoutProtocol.indexOf('/');
|
||||
|
||||
if(firstSlash === -1) {
|
||||
uri.host = uri.path;
|
||||
uri.path = "";
|
||||
} else {
|
||||
uri.host = withoutProtocol.slice(0, firstSlash);
|
||||
uri.path = withoutProtocol.slice(firstSlash);
|
||||
}
|
||||
|
||||
|
||||
uri.origin = uri.protocol + "://" + uri.host;
|
||||
|
||||
uri.directory = EPUBJS.core.folder(uri.path);
|
||||
|
||||
uri.base = uri.origin + uri.directory;
|
||||
// return origin;
|
||||
} else {
|
||||
uri.path = url;
|
||||
uri.directory = EPUBJS.core.folder(url);
|
||||
uri.base = uri.directory;
|
||||
}
|
||||
|
||||
//-- Filename
|
||||
uri.filename = url.replace(uri.base, '');
|
||||
dot = uri.filename.lastIndexOf('.');
|
||||
if(dot != -1) {
|
||||
uri.extension = uri.filename.slice(dot+1);
|
||||
}
|
||||
return uri;
|
||||
};
|
||||
|
||||
//-- Parse out the folder, will return everything before the last slash
|
||||
EPUBJS.core.folder = function(url){
|
||||
|
||||
var lastSlash = url.lastIndexOf('/');
|
||||
|
||||
if(lastSlash == -1) var folder = '';
|
||||
|
||||
folder = url.slice(0, lastSlash + 1);
|
||||
|
||||
return folder;
|
||||
|
||||
};
|
503
lib/epubjs/epubcfi.js
Normal file
503
lib/epubjs/epubcfi.js
Normal file
|
@ -0,0 +1,503 @@
|
|||
EPUBJS.EpubCFI = function(cfiStr){
|
||||
if(cfiStr) return this.parse(cfiStr);
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateChapterComponent = function(_spineNodeIndex, _pos, id) {
|
||||
var pos = parseInt(_pos),
|
||||
spineNodeIndex = _spineNodeIndex + 1,
|
||||
cfi = '/'+spineNodeIndex+'/';
|
||||
|
||||
cfi += (pos + 1) * 2;
|
||||
|
||||
if(id) cfi += "[" + id + "]";
|
||||
|
||||
//cfi += "!";
|
||||
|
||||
return cfi;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generatePathComponent = function(steps) {
|
||||
var parts = [];
|
||||
|
||||
steps.forEach(function(part){
|
||||
var segment = '';
|
||||
segment += (part.index + 1) * 2;
|
||||
|
||||
if(part.id) {
|
||||
segment += "[" + part.id + "]";
|
||||
}
|
||||
|
||||
parts.push(segment);
|
||||
});
|
||||
|
||||
return parts.join('/');
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateCfiFromElement = function(element, chapter) {
|
||||
var steps = this.pathTo(element);
|
||||
var path = this.generatePathComponent(steps);
|
||||
if(!path.length) {
|
||||
// Start of Chapter
|
||||
return "epubcfi(" + chapter + "!/4/)";
|
||||
} else {
|
||||
// First Text Node
|
||||
return "epubcfi(" + chapter + "!" + path + "/1:0)";
|
||||
}
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.pathTo = function(node) {
|
||||
var stack = [],
|
||||
children;
|
||||
|
||||
while(node && node.parentNode !== null && node.parentNode.nodeType != 9) {
|
||||
children = node.parentNode.children;
|
||||
|
||||
stack.unshift({
|
||||
'id' : node.id,
|
||||
// 'classList' : node.classList,
|
||||
'tagName' : node.tagName,
|
||||
'index' : children ? Array.prototype.indexOf.call(children, node) : 0
|
||||
});
|
||||
|
||||
node = node.parentNode;
|
||||
}
|
||||
|
||||
return stack;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.getChapterComponent = function(cfiStr) {
|
||||
|
||||
var splitStr = cfiStr.split("!");
|
||||
|
||||
return splitStr[0];
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.getPathComponent = function(cfiStr) {
|
||||
|
||||
var splitStr = cfiStr.split("!");
|
||||
var pathComponent = splitStr[1] ? splitStr[1].split(":") : '';
|
||||
|
||||
return pathComponent[0];
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent = function(cfiStr) {
|
||||
var splitStr = cfiStr.split(":");
|
||||
return splitStr[1] || '';
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.EpubCFI.prototype.parse = function(cfiStr) {
|
||||
var cfi = {},
|
||||
chapSegment,
|
||||
chapterComponent,
|
||||
pathComponent,
|
||||
charecterOffsetComponent,
|
||||
assertion,
|
||||
chapId,
|
||||
path,
|
||||
end,
|
||||
endInt,
|
||||
text,
|
||||
parseStep = function(part){
|
||||
var type, index, has_brackets, id;
|
||||
|
||||
type = "element";
|
||||
index = parseInt(part) / 2 - 1;
|
||||
has_brackets = part.match(/\[(.*)\]/);
|
||||
if(has_brackets && has_brackets[1]){
|
||||
id = has_brackets[1];
|
||||
}
|
||||
|
||||
return {
|
||||
"type" : type,
|
||||
'index' : index,
|
||||
'id' : id || false
|
||||
};
|
||||
};
|
||||
|
||||
if(typeof cfiStr !== "string") {
|
||||
return {spinePos: -1};
|
||||
}
|
||||
|
||||
cfi.str = cfiStr;
|
||||
|
||||
if(cfiStr.indexOf("epubcfi(") === 0 && cfiStr[cfiStr.length-1] === ")") {
|
||||
// Remove intial epubcfi( and ending )
|
||||
cfiStr = cfiStr.slice(8, cfiStr.length-1);
|
||||
}
|
||||
|
||||
chapterComponent = this.getChapterComponent(cfiStr);
|
||||
pathComponent = this.getPathComponent(cfiStr) || '';
|
||||
charecterOffsetComponent = this.getCharecterOffsetComponent(cfiStr);
|
||||
// Make sure this is a valid cfi or return
|
||||
if(!chapterComponent) {
|
||||
return {spinePos: -1};
|
||||
}
|
||||
|
||||
// Chapter segment is always the second one
|
||||
chapSegment = chapterComponent.split("/")[2] || '';
|
||||
if(!chapSegment) return {spinePos:-1};
|
||||
|
||||
cfi.spinePos = (parseInt(chapSegment) / 2 - 1 ) || 0;
|
||||
|
||||
chapId = chapSegment.match(/\[(.*)\]/);
|
||||
|
||||
cfi.spineId = chapId ? chapId[1] : false;
|
||||
|
||||
if(pathComponent.indexOf(',') != -1) {
|
||||
// Handle ranges -- not supported yet
|
||||
console.warn("CFI Ranges are not supported");
|
||||
}
|
||||
|
||||
path = pathComponent.split('/');
|
||||
end = path.pop();
|
||||
|
||||
cfi.steps = [];
|
||||
|
||||
path.forEach(function(part){
|
||||
var step;
|
||||
|
||||
if(part) {
|
||||
step = parseStep(part);
|
||||
cfi.steps.push(step);
|
||||
}
|
||||
});
|
||||
|
||||
//-- Check if END is a text node or element
|
||||
endInt = parseInt(end);
|
||||
if(!isNaN(endInt)) {
|
||||
|
||||
if(endInt % 2 === 0) { // Even = is an element
|
||||
cfi.steps.push(parseStep(end));
|
||||
} else {
|
||||
cfi.steps.push({
|
||||
"type" : "text",
|
||||
'index' : (endInt - 1 ) / 2
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assertion = charecterOffsetComponent.match(/\[(.*)\]/);
|
||||
if(assertion && assertion[1]){
|
||||
cfi.characterOffset = parseInt(charecterOffsetComponent.split('[')[0]);
|
||||
// We arent handling these assertions yet
|
||||
cfi.textLocationAssertion = assertion[1];
|
||||
} else {
|
||||
cfi.characterOffset = parseInt(charecterOffsetComponent);
|
||||
}
|
||||
|
||||
return cfi;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) {
|
||||
var doc = _doc || document;
|
||||
var marker = _marker || this.createMarker(doc);
|
||||
var parent;
|
||||
var lastStep;
|
||||
var text;
|
||||
var split;
|
||||
|
||||
if(typeof cfi === 'string') {
|
||||
cfi = this.parse(cfi);
|
||||
}
|
||||
// Get the terminal step
|
||||
lastStep = cfi.steps[cfi.steps.length-1];
|
||||
|
||||
// check spinePos
|
||||
if(cfi.spinePos === -1) {
|
||||
// Not a valid CFI
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the CFI elements parent
|
||||
parent = this.findParent(cfi, doc);
|
||||
|
||||
if(!parent) {
|
||||
// CFI didn't return an element
|
||||
// Maybe it isnt in the current chapter?
|
||||
return false;
|
||||
}
|
||||
|
||||
if(lastStep && lastStep.type === "text") {
|
||||
text = parent.childNodes[lastStep.index];
|
||||
if(cfi.characterOffset){
|
||||
split = text.splitText(cfi.characterOffset);
|
||||
marker.classList.add("EPUBJS-CFI-SPLIT");
|
||||
parent.insertBefore(marker, split);
|
||||
} else {
|
||||
parent.insertBefore(marker, text);
|
||||
}
|
||||
} else {
|
||||
parent.insertBefore(marker, parent.firstChild);
|
||||
}
|
||||
|
||||
return marker;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.createMarker = function(_doc) {
|
||||
var doc = _doc || document;
|
||||
var element = doc.createElement('span');
|
||||
element.id = "EPUBJS-CFI-MARKER:"+ EPUBJS.core.uuid();
|
||||
element.classList.add("EPUBJS-CFI-MARKER");
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) {
|
||||
var doc = _doc || document;
|
||||
// var id = marker.id;
|
||||
|
||||
// Cleanup textnodes if they were split
|
||||
if(marker.classList.contains("EPUBJS-CFI-SPLIT")){
|
||||
nextSib = marker.nextSibling;
|
||||
prevSib = marker.previousSibling;
|
||||
if(nextSib &&
|
||||
prevSib &&
|
||||
nextSib.nodeType === 3 &&
|
||||
prevSib.nodeType === 3){
|
||||
|
||||
prevSib.textContent += nextSib.textContent;
|
||||
marker.parentNode.removeChild(nextSib);
|
||||
}
|
||||
marker.parentNode.removeChild(marker);
|
||||
} else if(marker.classList.contains("EPUBJS-CFI-MARKER")) {
|
||||
// Remove only elements added as markers
|
||||
marker.parentNode.removeChild(marker);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.findParent = function(cfi, _doc) {
|
||||
var doc = _doc || document,
|
||||
element = doc.getElementsByTagName('html')[0],
|
||||
children = Array.prototype.slice.call(element.children),
|
||||
num, index, part, sections,
|
||||
text, textBegin, textEnd;
|
||||
|
||||
if(typeof cfi === 'string') {
|
||||
cfi = this.parse(cfi);
|
||||
}
|
||||
|
||||
sections = cfi.steps.slice(0); // Clone steps array
|
||||
if(!sections.length) {
|
||||
return doc.getElementsByTagName('body')[0];
|
||||
}
|
||||
|
||||
while(sections && sections.length > 0) {
|
||||
part = sections.shift();
|
||||
// Find textNodes Parent
|
||||
if(part.type === "text") {
|
||||
text = element.childNodes[part.index];
|
||||
element = text.parentNode || element;
|
||||
// Find element by id if present
|
||||
} else if(part.id){
|
||||
element = doc.getElementById(part.id);
|
||||
// Find element in parent
|
||||
}else{
|
||||
element = children[part.index];
|
||||
}
|
||||
// Element can't be found
|
||||
if(typeof element === "undefined") {
|
||||
console.error("No Element For", part, cfi.str);
|
||||
return false;
|
||||
}
|
||||
// Get current element children and continue through steps
|
||||
children = Array.prototype.slice.call(element.children);
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.compare = function(cfiOne, cfiTwo) {
|
||||
if(typeof cfiOne === 'string') {
|
||||
cfiOne = new EPUBJS.EpubCFI(cfiOne);
|
||||
}
|
||||
if(typeof cfiTwo === 'string') {
|
||||
cfiTwo = new EPUBJS.EpubCFI(cfiTwo);
|
||||
}
|
||||
// Compare Spine Positions
|
||||
if(cfiOne.spinePos > cfiTwo.spinePos) {
|
||||
return 1;
|
||||
}
|
||||
if(cfiOne.spinePos < cfiTwo.spinePos) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Compare Each Step in the First item
|
||||
for (var i = 0; i < cfiOne.steps.length; i++) {
|
||||
if(!cfiTwo.steps[i]) {
|
||||
return 1;
|
||||
}
|
||||
if(cfiOne.steps[i].index > cfiTwo.steps[i].index) {
|
||||
return 1;
|
||||
}
|
||||
if(cfiOne.steps[i].index < cfiTwo.steps[i].index) {
|
||||
return -1;
|
||||
}
|
||||
// Otherwise continue checking
|
||||
}
|
||||
|
||||
// All steps in First present in Second
|
||||
if(cfiOne.steps.length < cfiTwo.steps.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Compare the charecter offset of the text node
|
||||
if(cfiOne.characterOffset > cfiTwo.characterOffset) {
|
||||
return 1;
|
||||
}
|
||||
if(cfiOne.characterOffset < cfiTwo.characterOffset) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// CFI's are equal
|
||||
return 0;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateCfiFromHref = function(href, book) {
|
||||
var uri = EPUBJS.core.uri(href);
|
||||
var path = uri.path;
|
||||
var fragment = uri.fragment;
|
||||
var spinePos = book.spineIndexByURL[path];
|
||||
var loaded;
|
||||
var deferred = new RSVP.defer();
|
||||
var epubcfi = new EPUBJS.EpubCFI();
|
||||
var spineItem;
|
||||
|
||||
if(typeof spinePos !== "undefined"){
|
||||
spineItem = book.spine[spinePos];
|
||||
loaded = book.loadXml(spineItem.url);
|
||||
loaded.then(function(doc){
|
||||
var element = doc.getElementById(fragment);
|
||||
var cfi;
|
||||
cfi = epubcfi.generateCfiFromElement(element, spineItem.cfiBase);
|
||||
deferred.resolve(cfi);
|
||||
});
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateCfiFromTextNode = function(anchor, offset, base) {
|
||||
var parent = anchor.parentNode;
|
||||
var steps = this.pathTo(parent);
|
||||
var path = this.generatePathComponent(steps);
|
||||
var index = 1 + (2 * Array.prototype.indexOf.call(parent.childNodes, anchor));
|
||||
return "epubcfi(" + base + "!" + path + "/"+index+":"+(offset || 0)+")";
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateCfiFromRangeAnchor = function(range, base) {
|
||||
var anchor = range.anchorNode;
|
||||
var offset = range.anchorOffset;
|
||||
return this.generateCfiFromTextNode(anchor, offset, base);
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateCfiFromRange = function(range, base) {
|
||||
var start, startElement, startSteps, startPath, startOffset, startIndex;
|
||||
var end, endElement, endSteps, endPath, endOffset, endIndex;
|
||||
|
||||
start = range.startContainer;
|
||||
|
||||
if(start.nodeType === 3) { // text node
|
||||
startElement = start.parentNode;
|
||||
//startIndex = 1 + (2 * Array.prototype.indexOf.call(startElement.childNodes, start));
|
||||
startIndex = 1 + (2 * EPUBJS.core.indexOfTextNode(start));
|
||||
startSteps = this.pathTo(startElement);
|
||||
} else if(range.collapsed) {
|
||||
return this.generateCfiFromElement(start, base); // single element
|
||||
} else {
|
||||
startSteps = this.pathTo(start);
|
||||
}
|
||||
|
||||
startPath = this.generatePathComponent(startSteps);
|
||||
startOffset = range.startOffset;
|
||||
|
||||
if(!range.collapsed) {
|
||||
end = range.endContainer;
|
||||
|
||||
if(end.nodeType === 3) { // text node
|
||||
endElement = end.parentNode;
|
||||
// endIndex = 1 + (2 * Array.prototype.indexOf.call(endElement.childNodes, end));
|
||||
endIndex = 1 + (2 * EPUBJS.core.indexOfTextNode(end));
|
||||
|
||||
endSteps = this.pathTo(endElement);
|
||||
} else {
|
||||
endSteps = this.pathTo(end);
|
||||
}
|
||||
|
||||
endPath = this.generatePathComponent(endSteps);
|
||||
endOffset = range.endOffset;
|
||||
|
||||
return "epubcfi(" + base + "!" + startPath + "/" + startIndex + ":" + startOffset + "," + endPath + "/" + endIndex + ":" + endOffset + ")";
|
||||
|
||||
} else {
|
||||
return "epubcfi(" + base + "!" + startPath + "/"+ startIndex +":"+ startOffset +")";
|
||||
}
|
||||
};
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateXpathFromSteps = function(steps) {
|
||||
var xpath = [".", "*"];
|
||||
|
||||
steps.forEach(function(step){
|
||||
var position = step.index + 1;
|
||||
|
||||
if(step.id){
|
||||
xpath.push("*[position()=" + position + " and @id='" + step.id + "']");
|
||||
} else if(step.type === "text") {
|
||||
xpath.push("text()[" + position + "]");
|
||||
} else {
|
||||
xpath.push("*[" + position + "]");
|
||||
}
|
||||
});
|
||||
|
||||
return xpath.join("/");
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.EpubCFI.prototype.generateRangeFromCfi = function(cfi, _doc) {
|
||||
var doc = _doc || document;
|
||||
var range = doc.createRange();
|
||||
var lastStep;
|
||||
var xpath;
|
||||
var startContainer;
|
||||
var textLength;
|
||||
|
||||
if(typeof cfi === 'string') {
|
||||
cfi = this.parse(cfi);
|
||||
}
|
||||
|
||||
// check spinePos
|
||||
if(cfi.spinePos === -1) {
|
||||
// Not a valid CFI
|
||||
return false;
|
||||
}
|
||||
|
||||
xpath = this.generateXpathFromSteps(cfi.steps);
|
||||
|
||||
// Get the terminal step
|
||||
lastStep = cfi.steps[cfi.steps.length-1];
|
||||
startContainer = doc.evaluate(xpath, doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
|
||||
if(!startContainer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(startContainer && cfi.characterOffset >= 0) {
|
||||
textLength = startContainer.length;
|
||||
|
||||
if(cfi.characterOffset < textLength) {
|
||||
range.setStart(startContainer, cfi.characterOffset);
|
||||
range.setEnd(startContainer, textLength );
|
||||
} else {
|
||||
console.debug("offset greater than length:", cfi.characterOffset, textLength);
|
||||
range.setStart(startContainer, textLength - 1 );
|
||||
range.setEnd(startContainer, textLength );
|
||||
}
|
||||
} else if(startContainer) {
|
||||
range.selectNode(startContainer);
|
||||
}
|
||||
// doc.defaultView.getSelection().addRange(range);
|
||||
return range;
|
||||
};
|
91
lib/epubjs/navigation.js
Normal file
91
lib/epubjs/navigation.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
EPUBJS.Navigation = function(_package, _request){
|
||||
var navigation = this;
|
||||
var parse = new EPUBJS.Parser();
|
||||
var request = _request || EPUBJS.core.request;
|
||||
|
||||
this.package = _package;
|
||||
this.toc = [];
|
||||
this.tocByHref = {};
|
||||
this.tocById = {};
|
||||
|
||||
if(_package.navPath) {
|
||||
this.navUrl = _package.baseUrl + _package.navPath;
|
||||
this.nav = {};
|
||||
|
||||
this.nav.load = function(_request){
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
|
||||
request(navigation.navUrl, 'xml').then(function(xml){
|
||||
navigation.toc = parse.nav(xml);
|
||||
navigation.loaded(navigation.toc);
|
||||
loading.resolve(navigation.toc);
|
||||
});
|
||||
|
||||
return loaded;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if(_package.ncxPath) {
|
||||
this.ncxUrl = _package.baseUrl + _package.ncxPath;
|
||||
this.ncx = {};
|
||||
|
||||
this.ncx.load = function(_request){
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
|
||||
request(navigation.ncxUrl, 'xml').then(function(xml){
|
||||
navigation.toc = parse.ncx(xml);
|
||||
navigation.loaded(navigation.toc);
|
||||
loading.resolve(navigation.toc);
|
||||
});
|
||||
|
||||
return loaded;
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Load the navigation
|
||||
EPUBJS.Navigation.prototype.load = function(_request) {
|
||||
var request = _request || EPUBJS.core.request;
|
||||
var loading;
|
||||
|
||||
if(this.nav) {
|
||||
loading = this.nav.load();
|
||||
} else if(this.ncx) {
|
||||
loading = this.ncx.load();
|
||||
}
|
||||
|
||||
return loading;
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Navigation.prototype.loaded = function(toc) {
|
||||
var item;
|
||||
|
||||
for (var i = 0; i < toc.length; i++) {
|
||||
var item = toc[i];
|
||||
this.tocByHref[item.href] = i;
|
||||
this.tocById[item.id] = i;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// Get an item from the navigation
|
||||
EPUBJS.Navigation.prototype.get = function(target) {
|
||||
var index;
|
||||
|
||||
if(!target) {
|
||||
return this.toc;
|
||||
}
|
||||
|
||||
if(target.indexOf("#") === 0) {
|
||||
index = this.tocById[target.substring(1)];
|
||||
} else if(target in this.tocByHref){
|
||||
index = this.tocByHref[target];
|
||||
}
|
||||
|
||||
return this.toc[index];
|
||||
};
|
365
lib/epubjs/parser.js
Normal file
365
lib/epubjs/parser.js
Normal file
|
@ -0,0 +1,365 @@
|
|||
EPUBJS.Parser = function(){};
|
||||
|
||||
EPUBJS.Parser.prototype.container = function(containerXml){
|
||||
//-- <rootfile full-path="OPS/package.opf" media-type="application/oebps-package+xml"/>
|
||||
var rootfile, fullpath, folder, encoding;
|
||||
|
||||
if(!containerXml) {
|
||||
console.error("Container File Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
rootfile = containerXml.querySelector("rootfile");
|
||||
|
||||
if(!rootfile) {
|
||||
console.error("No RootFile Found");
|
||||
return;
|
||||
}
|
||||
|
||||
fullpath = rootfile.getAttribute('full-path');
|
||||
folder = EPUBJS.core.uri(fullpath).directory;
|
||||
encoding = containerXml.xmlEncoding;
|
||||
|
||||
//-- Now that we have the path we can parse the contents
|
||||
return {
|
||||
'packagePath' : fullpath,
|
||||
'basePath' : folder,
|
||||
'encoding' : encoding
|
||||
};
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.identifier = function(packageXml){
|
||||
var metadataNode;
|
||||
|
||||
if(!packageXml) {
|
||||
console.error("Package File Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
metadataNode = packageXml.querySelector("metadata");
|
||||
|
||||
if(!metadataNode) {
|
||||
console.error("No Metadata Found");
|
||||
return;
|
||||
}
|
||||
|
||||
return this.getElementText(metadataNode, "identifier");
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.packageContents = function(packageXml){
|
||||
var parse = this;
|
||||
var metadataNode, manifestNode, spineNode;
|
||||
var manifest, navPath, ncxPath, coverPath;
|
||||
var spineNodeIndex;
|
||||
var spine;
|
||||
var spineIndexByURL;
|
||||
|
||||
if(!packageXml) {
|
||||
console.error("Package File Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
metadataNode = packageXml.querySelector("metadata");
|
||||
if(!metadataNode) {
|
||||
console.error("No Metadata Found");
|
||||
return;
|
||||
}
|
||||
|
||||
manifestNode = packageXml.querySelector("manifest");
|
||||
if(!manifestNode) {
|
||||
console.error("No Manifest Found");
|
||||
return;
|
||||
}
|
||||
|
||||
spineNode = packageXml.querySelector("spine");
|
||||
if(!spineNode) {
|
||||
console.error("No Spine Found");
|
||||
return;
|
||||
}
|
||||
|
||||
manifest = parse.manifest(manifestNode);
|
||||
navPath = parse.findNavPath(manifestNode);
|
||||
ncxPath = parse.findNcxPath(manifestNode);
|
||||
coverPath = parse.findCoverPath(manifestNode);
|
||||
|
||||
spineNodeIndex = Array.prototype.indexOf.call(spineNode.parentNode.childNodes, spineNode);
|
||||
|
||||
spine = parse.spine(spineNode, manifest);
|
||||
|
||||
return {
|
||||
'metadata' : parse.metadata(metadataNode),
|
||||
'spine' : spine,
|
||||
'manifest' : manifest,
|
||||
'navPath' : navPath,
|
||||
'ncxPath' : ncxPath,
|
||||
'coverPath': coverPath,
|
||||
'spineNodeIndex' : spineNodeIndex
|
||||
};
|
||||
};
|
||||
|
||||
//-- Find TOC NAV: media-type="application/xhtml+xml" href="toc.ncx"
|
||||
EPUBJS.Parser.prototype.findNavPath = function(manifestNode){
|
||||
var node = manifestNode.querySelector("item[properties^='nav']");
|
||||
return node ? node.getAttribute('href') : false;
|
||||
};
|
||||
|
||||
//-- Find TOC NCX: media-type="application/x-dtbncx+xml" href="toc.ncx"
|
||||
EPUBJS.Parser.prototype.findNcxPath = function(manifestNode){
|
||||
var node = manifestNode.querySelector("item[media-type='application/x-dtbncx+xml']");
|
||||
return node ? node.getAttribute('href') : false;
|
||||
};
|
||||
|
||||
//-- Find Cover: <item properties="cover-image" id="ci" href="cover.svg" media-type="image/svg+xml" />
|
||||
EPUBJS.Parser.prototype.findCoverPath = function(manifestNode){
|
||||
var node = manifestNode.querySelector("item[properties='cover-image']");
|
||||
return node ? node.getAttribute('href') : false;
|
||||
};
|
||||
|
||||
//-- Expanded to match Readium web components
|
||||
EPUBJS.Parser.prototype.metadata = function(xml){
|
||||
var metadata = {},
|
||||
p = this;
|
||||
|
||||
metadata.title = p.getElementText(xml, 'title');
|
||||
metadata.creator = p.getElementText(xml, 'creator');
|
||||
metadata.description = p.getElementText(xml, 'description');
|
||||
|
||||
metadata.pubdate = p.getElementText(xml, 'date');
|
||||
|
||||
metadata.publisher = p.getElementText(xml, 'publisher');
|
||||
|
||||
metadata.identifier = p.getElementText(xml, "identifier");
|
||||
metadata.language = p.getElementText(xml, "language");
|
||||
metadata.rights = p.getElementText(xml, "rights");
|
||||
|
||||
metadata.modified_date = p.querySelectorText(xml, "meta[property='dcterms:modified']");
|
||||
metadata.layout = p.querySelectorText(xml, "meta[property='rendition:layout']");
|
||||
metadata.orientation = p.querySelectorText(xml, "meta[property='rendition:orientation']");
|
||||
metadata.spread = p.querySelectorText(xml, "meta[property='rendition:spread']");
|
||||
// metadata.page_prog_dir = packageXml.querySelector("spine").getAttribute("page-progression-direction");
|
||||
|
||||
return metadata;
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.getElementText = function(xml, tag){
|
||||
var found = xml.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/", tag),
|
||||
el;
|
||||
|
||||
if(!found || found.length === 0) return '';
|
||||
|
||||
el = found[0];
|
||||
|
||||
if(el.childNodes.length){
|
||||
return el.childNodes[0].nodeValue;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.querySelectorText = function(xml, q){
|
||||
var el = xml.querySelector(q);
|
||||
|
||||
if(el && el.childNodes.length){
|
||||
return el.childNodes[0].nodeValue;
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.manifest = function(manifestXml){
|
||||
var manifest = {};
|
||||
|
||||
//-- Turn items into an array
|
||||
var selected = manifestXml.querySelectorAll("item"),
|
||||
items = Array.prototype.slice.call(selected);
|
||||
|
||||
//-- Create an object with the id as key
|
||||
items.forEach(function(item){
|
||||
var id = item.getAttribute('id'),
|
||||
href = item.getAttribute('href') || '',
|
||||
type = item.getAttribute('media-type') || '',
|
||||
properties = item.getAttribute('properties') || '';
|
||||
|
||||
manifest[id] = {
|
||||
'href' : href,
|
||||
// 'url' : href,
|
||||
'type' : type,
|
||||
'properties' : properties
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
return manifest;
|
||||
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.spine = function(spineXml, manifest){
|
||||
var spine = [];
|
||||
|
||||
var selected = spineXml.getElementsByTagName("itemref"),
|
||||
items = Array.prototype.slice.call(selected);
|
||||
|
||||
// var epubcfi = new EPUBJS.EpubCFI();
|
||||
|
||||
//-- Add to array to mantain ordering and cross reference with manifest
|
||||
items.forEach(function(item, index){
|
||||
var idref = item.getAttribute('idref');
|
||||
// var cfiBase = epubcfi.generateChapterComponent(spineNodeIndex, index, Id);
|
||||
var props = item.getAttribute('properties') || '';
|
||||
var propArray = props.length ? props.split(' ') : [];
|
||||
// var manifestProps = manifest[Id].properties;
|
||||
// var manifestPropArray = manifestProps.length ? manifestProps.split(' ') : [];
|
||||
var itemref = {
|
||||
'idref' : idref,
|
||||
'linear' : item.getAttribute('linear') || '',
|
||||
'properties' : propArray,
|
||||
// 'href' : manifest[Id].href,
|
||||
// 'url' : manifest[Id].url,
|
||||
'index' : index,
|
||||
};
|
||||
spine.push(itemref);
|
||||
});
|
||||
|
||||
return spine;
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.nav = function(navHtml){
|
||||
var navEl = navHtml.querySelector('nav[*|type="toc"]'), //-- [*|type="toc"] * Doesn't seem to work
|
||||
idCounter = 0;
|
||||
|
||||
if(!navEl) return [];
|
||||
|
||||
// Implements `> ol > li`
|
||||
function findListItems(parent){
|
||||
var items = [];
|
||||
|
||||
Array.prototype.slice.call(parent.childNodes).forEach(function(node){
|
||||
if('ol' == node.tagName){
|
||||
Array.prototype.slice.call(node.childNodes).forEach(function(item){
|
||||
if('li' == item.tagName){
|
||||
items.push(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
|
||||
}
|
||||
|
||||
// Implements `> a, > span`
|
||||
function findAnchorOrSpan(parent){
|
||||
var item = null;
|
||||
|
||||
Array.prototype.slice.call(parent.childNodes).forEach(function(node){
|
||||
if('a' == node.tagName || 'span' == node.tagName){
|
||||
item = node;
|
||||
}
|
||||
});
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
function getTOC(parent){
|
||||
var list = [],
|
||||
nodes = findListItems(parent),
|
||||
items = Array.prototype.slice.call(nodes),
|
||||
length = items.length,
|
||||
node;
|
||||
|
||||
if(length === 0) return false;
|
||||
|
||||
items.forEach(function(item){
|
||||
var id = item.getAttribute('id') || false,
|
||||
content = findAnchorOrSpan(item),
|
||||
href = content.getAttribute('href') || '',
|
||||
text = content.textContent || "",
|
||||
split = href.split("#"),
|
||||
baseUrl = split[0],
|
||||
subitems = getTOC(item);
|
||||
// spinePos = spineIndexByURL[baseUrl],
|
||||
// spineItem = bookSpine[spinePos],
|
||||
// cfi = spineItem ? spineItem.cfi : '';
|
||||
|
||||
// if(!id) {
|
||||
// if(spinePos) {
|
||||
// spineItem = bookSpine[spinePos];
|
||||
// id = spineItem.id;
|
||||
// cfi = spineItem.cfi;
|
||||
// } else {
|
||||
// id = 'epubjs-autogen-toc-id-' + (idCounter++);
|
||||
// }
|
||||
// }
|
||||
|
||||
// item.setAttribute('id', id); // Ensure all elements have an id
|
||||
list.push({
|
||||
"id": id,
|
||||
"href": href,
|
||||
"label": text,
|
||||
"subitems" : subitems,
|
||||
"parent" : parent ? parent.getAttribute('id') : null
|
||||
// "cfi" : cfi
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return getTOC(navEl);
|
||||
};
|
||||
|
||||
EPUBJS.Parser.prototype.ncx = function(tocXml){
|
||||
var navMap = tocXml.querySelector("navMap");
|
||||
if(!navMap) return [];
|
||||
|
||||
function getTOC(parent){
|
||||
var list = [],
|
||||
snapshot = tocXml.evaluate("*[local-name()='navPoint']", parent, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null),
|
||||
length = snapshot.snapshotLength;
|
||||
|
||||
if(length === 0) return [];
|
||||
|
||||
for ( var i=length-1 ; i >= 0; i-- ) {
|
||||
var item = snapshot.snapshotItem(i);
|
||||
|
||||
var id = item.getAttribute('id') || false,
|
||||
content = item.querySelector("content"),
|
||||
src = content.getAttribute('src'),
|
||||
navLabel = item.querySelector("navLabel"),
|
||||
text = navLabel.textContent ? navLabel.textContent : "",
|
||||
split = src.split("#"),
|
||||
baseUrl = split[0],
|
||||
// spinePos = spineIndexByURL[baseUrl],
|
||||
// spineItem = bookSpine[spinePos],
|
||||
subitems = getTOC(item);
|
||||
// cfi = spineItem ? spineItem.cfi : '';
|
||||
|
||||
// if(!id) {
|
||||
// if(spinePos) {
|
||||
// spineItem = bookSpine[spinePos];
|
||||
// id = spineItem.id;
|
||||
// cfi = spineItem.cfi;
|
||||
// } else {
|
||||
// id = 'epubjs-autogen-toc-id-' + (idCounter++);
|
||||
// }
|
||||
// }
|
||||
|
||||
list.unshift({
|
||||
"id": id,
|
||||
"href": src,
|
||||
"label": text,
|
||||
// "spinePos": spinePos,
|
||||
"subitems" : subitems,
|
||||
"parent" : parent ? parent.getAttribute('id') : null,
|
||||
// "cfi" : cfi
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return getTOC(navMap);
|
||||
};
|
91
lib/epubjs/spine.js
Normal file
91
lib/epubjs/spine.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
EPUBJS.Spine = function(_package, _request){
|
||||
this.items = _package.spine;
|
||||
this.manifest = _package.manifest;
|
||||
this.spineNodeIndex = _package.spineNodeIndex;
|
||||
this.baseUrl = _package.baseUrl || '';
|
||||
this.request = _request;
|
||||
this.length = this.items.length;
|
||||
this.epubcfi = new EPUBJS.EpubCFI();
|
||||
this.spineItems = [];
|
||||
this.spineByHref = {};
|
||||
this.spineById = {};
|
||||
|
||||
this.items.forEach(function(item, index){
|
||||
var cfiBase = this.epubcfi.generateChapterComponent(this.spineNodeIndex, item.index, item.idref);
|
||||
var href, url;
|
||||
var manifestItem = this.manifest[item.idref];
|
||||
var spineItem;
|
||||
|
||||
if(manifestItem) {
|
||||
href = manifestItem.href;
|
||||
url = this.baseUrl + href;
|
||||
}
|
||||
|
||||
spineItem = new EPUBJS.SpineItem(item, href, url, cfiBase);
|
||||
this.spineItems.push(spineItem);
|
||||
|
||||
this.spineByHref[spineItem.href] = index;
|
||||
this.spineById[spineItem.idref] = index;
|
||||
|
||||
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
|
||||
// book.spine.get();
|
||||
// book.spine.get(1);
|
||||
// book.spine.get("chap1.html");
|
||||
// book.spine.get("#id1234");
|
||||
EPUBJS.Spine.prototype.get = function(target) {
|
||||
var index = 1;
|
||||
|
||||
if(typeof target === "number" || isNaN(target) === false){
|
||||
index = target-1;
|
||||
} else if(target.indexOf("#") === 0) {
|
||||
index = this.spineById[target.substring(1)];
|
||||
} else {
|
||||
index = this.spineByHref[target];
|
||||
}
|
||||
|
||||
return this.spineItems[index];
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.SpineItem = function(item, href, url, cfiBase){
|
||||
this.idref = item.idref;
|
||||
this.linear = item.linear;
|
||||
this.properties = item.properties;
|
||||
this.index = item.index;
|
||||
this.href = href;
|
||||
this.url = url;
|
||||
this.cfiBase = cfiBase;
|
||||
};
|
||||
|
||||
|
||||
EPUBJS.SpineItem.prototype.load = function(_request){
|
||||
var request = _request || this.request || EPUBJS.core.request;
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
|
||||
if(this.contents) {
|
||||
loading.resolve(this.contents);
|
||||
} else {
|
||||
request(this.url, 'xml').then(function(xml){
|
||||
this.contents = xml.documentElement;
|
||||
loading.resolve(this.contents);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
return loaded;
|
||||
};
|
||||
|
||||
EPUBJS.SpineItem.prototype.render = function(){
|
||||
return this.load().then(function(contents){
|
||||
var serializer = new XMLSerializer();
|
||||
return serializer.serializeToString(contents);
|
||||
});
|
||||
};
|
||||
|
||||
EPUBJS.SpineItem.prototype.find = function(_query){
|
||||
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,892 +0,0 @@
|
|||
/* Base Reset
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-notice,
|
||||
.annotator-filter *,
|
||||
.annotator-widget * {
|
||||
font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
|
||||
font-weight: normal;
|
||||
text-align: left;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: none;
|
||||
-webkit-transition: none;
|
||||
-moz-transition: none;
|
||||
-o-transition: none;
|
||||
transition: none;
|
||||
-moz-box-shadow: none;
|
||||
-webkit-box-shadow: none;
|
||||
-o-box-shadow: none;
|
||||
box-shadow: none;
|
||||
color: rgb(144, 144, 144);
|
||||
}
|
||||
|
||||
/* Images
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-adder {
|
||||
background-image: url(../img/annotator-icon-sprite.png);
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.annotator-resize,
|
||||
.annotator-widget::after,
|
||||
.annotator-editor a::after,
|
||||
.annotator-viewer .annotator-controls button,
|
||||
.annotator-viewer .annotator-controls a,
|
||||
.annotator-filter .annotator-filter-navigation button::after,
|
||||
.annotator-filter .annotator-filter-property .annotator-filter-clear {
|
||||
background-image: url(../img/annotator-glyph-sprite.png);
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
/* Annotator Highlight
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-hl {
|
||||
background: rgba(255, 255, 10, 0.3);
|
||||
}
|
||||
|
||||
.annotator-hl-temporary {
|
||||
background: rgba(0, 124, 255, 0.3);
|
||||
}
|
||||
|
||||
/* Annotator Wrapper
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* NB: If you change the list of classes for which z-index is set,
|
||||
you should update Annotator._setupDynamicStyle() */
|
||||
.annotator-adder,
|
||||
.annotator-outer,
|
||||
.annotator-notice {
|
||||
z-index: 1020;
|
||||
}
|
||||
|
||||
.annotator-filter {
|
||||
z-index: 1010;
|
||||
}
|
||||
|
||||
.annotator-adder,
|
||||
.annotator-outer,
|
||||
.annotator-widget,
|
||||
.annotator-notice {
|
||||
position: absolute;
|
||||
font-size: 10px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.annotator-adder,
|
||||
.annotator-outer {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.annotator-hide {
|
||||
display: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
/* Annotator Adder
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-adder {
|
||||
margin-top: -48px;
|
||||
margin-left: -24px;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
background-position: left top;
|
||||
}
|
||||
|
||||
.annotator-adder:hover {
|
||||
background-position: center top;
|
||||
}
|
||||
|
||||
.annotator-adder:active {
|
||||
background-position: center right;
|
||||
}
|
||||
|
||||
.annotator-adder button {
|
||||
display: block;
|
||||
width: 36px;
|
||||
height: 41px;
|
||||
margin: 0 auto;
|
||||
border: none;
|
||||
background: none;
|
||||
text-indent: -999em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Annotator Widget
|
||||
|
||||
This applies to both the Viewer and the Editor
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-outer {
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.annotator-widget {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
bottom: 15px;
|
||||
left: -18px;
|
||||
min-width: 265px;
|
||||
background-color: rgba(251, 251, 251, 0.98);
|
||||
border: 1px solid rgba(122, 122, 122, 0.6);
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
-webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
-moz-box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
-o-box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.annotator-invert-x .annotator-widget {
|
||||
left: auto;
|
||||
right: -18px;
|
||||
}
|
||||
|
||||
.annotator-invert-y .annotator-widget {
|
||||
bottom: auto;
|
||||
top: 8px;
|
||||
}
|
||||
|
||||
.annotator-widget strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.annotator-widget .annotator-listing,
|
||||
.annotator-widget .annotator-item {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.annotator-widget::after {
|
||||
content: "";
|
||||
display: block;
|
||||
width: 18px;
|
||||
height: 10px;
|
||||
background-position: 0 0;
|
||||
position: absolute;
|
||||
bottom: -10px;
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
.annotator-invert-x .annotator-widget::after {
|
||||
left: auto;
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
.annotator-invert-y .annotator-widget::after {
|
||||
background-position: 0 -15px;
|
||||
bottom: auto;
|
||||
top: -9px;
|
||||
}
|
||||
|
||||
.annotator-widget .annotator-item,
|
||||
.annotator-editor .annotator-item input,
|
||||
.annotator-editor .annotator-item textarea {
|
||||
position: relative;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-item {
|
||||
border-top: 2px solid rgba(122, 122, 122, 0.2);
|
||||
}
|
||||
|
||||
.annotator-widget .annotator-item:first-child {
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item,
|
||||
.annotator-viewer div {
|
||||
border-top: 1px solid rgba(133, 133, 133, 0.11);
|
||||
}
|
||||
|
||||
/* Annotator Viewer
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-viewer div {
|
||||
padding: 6px 6px;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-item ol,
|
||||
.annotator-viewer .annotator-item ul {
|
||||
padding: 4px 16px;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-item li {
|
||||
}
|
||||
|
||||
.annotator-viewer div:first-of-type,
|
||||
.annotator-editor .annotator-item:first-child textarea {
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
color: rgb(60, 60, 60);
|
||||
font-size: 13px;
|
||||
font-style: italic;
|
||||
line-height: 1.3;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls {
|
||||
position: relative;
|
||||
top: 5px;
|
||||
right: 5px;
|
||||
padding-left: 5px;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s ease-in;
|
||||
-moz-transition: opacity 0.2s ease-in;
|
||||
-o-transition: opacity 0.2s ease-in;
|
||||
transition: opacity 0.2s ease-in;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.annotator-viewer li:hover .annotator-controls,
|
||||
.annotator-viewer li .annotator-controls.annotator-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls button,
|
||||
.annotator-viewer .annotator-controls a {
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
margin-left: 2px;
|
||||
border: none;
|
||||
opacity: 0.2;
|
||||
text-indent: -900em;
|
||||
background-color: transparent;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls button:hover,
|
||||
.annotator-viewer .annotator-controls button:focus,
|
||||
.annotator-viewer .annotator-controls a:hover,
|
||||
.annotator-viewer .annotator-controls a:focus {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls button:active,
|
||||
.annotator-viewer .annotator-controls a:active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls button[disabled] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls .annotator-edit {
|
||||
background-position: 0 -60px;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls .annotator-delete {
|
||||
background-position: 0 -75px;
|
||||
}
|
||||
|
||||
.annotator-viewer .annotator-controls .annotator-link {
|
||||
background-position: 0 -270px;
|
||||
}
|
||||
|
||||
/* Annotator Editor
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-editor .annotator-item {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item label {
|
||||
top: 0;
|
||||
display: inline;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item input,
|
||||
.annotator-editor .annotator-item textarea {
|
||||
display: block;
|
||||
min-width: 100%;
|
||||
padding: 10px 8px;
|
||||
border: none;
|
||||
margin: 0;
|
||||
color: rgb(60, 60, 60);
|
||||
background: none;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-o-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item textarea::-webkit-scrollbar {
|
||||
height: 8px;
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item textarea::-webkit-scrollbar-track-piece {
|
||||
margin: 13px 0 3px;
|
||||
background-color: #e5e5e5;
|
||||
-webkit-border-radius: 4px;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item textarea::-webkit-scrollbar-thumb:vertical {
|
||||
height: 25px;
|
||||
background-color: #ccc;
|
||||
-webkit-border-radius: 4px;
|
||||
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item textarea::-webkit-scrollbar-thumb:horizontal {
|
||||
width: 25px;
|
||||
background-color: #ccc;
|
||||
-webkit-border-radius: 4px;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item:first-child textarea {
|
||||
min-height: 5.5em;
|
||||
-webkit-border-radius: 5px 5px 0 0;
|
||||
-moz-border-radius: 5px 5px 0 0;
|
||||
-o-border-radius: 5px 5px 0 0;
|
||||
border-radius: 5px 5px 0 0;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item input:focus,
|
||||
.annotator-editor .annotator-item textarea:focus{
|
||||
background-color: rgb(243, 243, 243);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-item input[type=radio],
|
||||
.annotator-editor .annotator-item input[type=checkbox] {
|
||||
width: auto;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
display: inline;
|
||||
margin: 0 4px 0 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-checkbox {
|
||||
padding: 8px 6px;
|
||||
}
|
||||
|
||||
.annotator-filter,
|
||||
.annotator-filter .annotator-filter-navigation button,
|
||||
.annotator-editor .annotator-controls {
|
||||
text-align: right;
|
||||
padding: 3px;
|
||||
border-top: 1px solid rgb(212,212,212);
|
||||
background-color: rgb(212, 212, 212);
|
||||
background-image: -webkit-gradient(
|
||||
linear, left top, left bottom,
|
||||
from(rgb(245, 245, 245)),
|
||||
color-stop(0.6, rgb(220, 220, 220)),
|
||||
to(rgb(210, 210, 210))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
to bottom,
|
||||
rgb(245, 245, 245),
|
||||
rgb(220, 220, 220) 60%,
|
||||
rgb(210, 210, 210)
|
||||
);
|
||||
background-image: -webkit-linear-gradient(
|
||||
to bottom,
|
||||
rgb(245, 245, 245),
|
||||
rgb(220, 220, 220) 60%,
|
||||
rgb(210, 210, 210)
|
||||
);
|
||||
background-image: linear-gradient(
|
||||
to bottom,
|
||||
rgb(245, 245, 245),
|
||||
rgb(220, 220, 220) 60%,
|
||||
rgb(210, 210, 210)
|
||||
);
|
||||
-webkit-box-shadow:
|
||||
inset 1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset -1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
-moz-box-shadow:
|
||||
inset 1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset -1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
-o-box-shadow:
|
||||
inset 1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset -1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
box-shadow:
|
||||
inset 1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset -1px 0 0 rgba(255, 255, 255, 0.7),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
-webkit-border-radius: 0 0 5px 5px;
|
||||
-moz-border-radius: 0 0 5px 5px;
|
||||
-o-border-radius: 0 0 5px 5px;
|
||||
border-radius: 0 0 5px 5px;
|
||||
}
|
||||
|
||||
.annotator-editor.annotator-invert-y .annotator-controls {
|
||||
border-top: none;
|
||||
border-bottom: 1px solid rgb(180, 180, 180);
|
||||
-webkit-border-radius: 5px 5px 0 0;
|
||||
-moz-border-radius: 5px 5px 0 0;
|
||||
-o-border-radius: 5px 5px 0 0;
|
||||
border-radius: 5px 5px 0 0;
|
||||
}
|
||||
|
||||
.annotator-editor a,
|
||||
.annotator-filter .annotator-filter-property label {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
padding: 0 6px 0 22px;
|
||||
color: rgb(54, 54, 54);
|
||||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
|
||||
text-decoration: none;
|
||||
line-height: 24px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
border: 1px solid rgb(162, 162, 162);
|
||||
background-color: rgb(212, 212, 212);
|
||||
background-image: -webkit-gradient(
|
||||
linear, left top, left bottom,
|
||||
from(rgb(245, 245, 245)),
|
||||
color-stop(0.5, rgb(210, 210, 210)),
|
||||
color-stop(0.5, rgb(190, 190, 190)),
|
||||
to(rgb(210, 210, 210))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
to bottom,
|
||||
rgb(245, 245, 245),
|
||||
rgb(210, 210, 210) 50%,
|
||||
rgb(190, 190, 190) 50%,
|
||||
rgb(210, 210, 210)
|
||||
);
|
||||
background-image: -webkit-linear-gradient(
|
||||
to bottom,
|
||||
rgb(245, 245, 245),
|
||||
rgb(210, 210, 210) 50%,
|
||||
rgb(190, 190, 190) 50%,
|
||||
rgb(210, 210, 210)
|
||||
);
|
||||
background-image: linear-gradient(
|
||||
to bottom,
|
||||
rgb(245, 245, 245),
|
||||
rgb(210, 210, 210) 50%,
|
||||
rgb(190, 190, 190) 50%,
|
||||
rgb(210, 210, 210)
|
||||
);
|
||||
-webkit-box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
-moz-box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
-o-box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.annotator-editor a::after {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 5px;
|
||||
display: block;
|
||||
content: "";
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
margin-top: -7px;
|
||||
background-position: 0 -90px;
|
||||
}
|
||||
|
||||
.annotator-editor a:hover,
|
||||
.annotator-editor a:focus,
|
||||
.annotator-editor a.annotator-focus,
|
||||
.annotator-filter .annotator-filter-active label,
|
||||
.annotator-filter .annotator-filter-navigation button:hover {
|
||||
outline: none;
|
||||
border-color: rgb(67, 90, 160);
|
||||
background-color: rgb(56, 101, 249);
|
||||
background-image: -webkit-gradient(
|
||||
linear, left top, left bottom,
|
||||
from(rgb(118, 145, 251)),
|
||||
color-stop(0.5, rgb(80, 117, 251)),
|
||||
color-stop(0.5, rgb(56, 101, 249)),
|
||||
to(rgb(54, 101, 250))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
to bottom,
|
||||
rgb(118, 145, 251),
|
||||
rgb(80, 117, 251) 50%,
|
||||
rgb(56, 101, 249) 50%,
|
||||
rgb(54, 101, 250)
|
||||
);
|
||||
background-image: -webkit-linear-gradient(
|
||||
to bottom,
|
||||
rgb(118, 145, 251),
|
||||
rgb(80, 117, 251) 50%,
|
||||
rgb(56, 101, 249) 50%,
|
||||
rgb(54, 101, 250)
|
||||
);
|
||||
background-image: linear-gradient(
|
||||
to bottom,
|
||||
rgb(118, 145, 251),
|
||||
rgb(80, 117, 251) 50%,
|
||||
rgb(56, 101, 249) 50%,
|
||||
rgb(54, 101, 250)
|
||||
);
|
||||
color: rgb(255, 255, 255);
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.42);
|
||||
}
|
||||
|
||||
.annotator-editor a:hover::after,
|
||||
.annotator-editor a:focus::after {
|
||||
margin-top: -8px;
|
||||
background-position: 0 -105px;
|
||||
}
|
||||
|
||||
.annotator-editor a:active,
|
||||
.annotator-filter .annotator-filter-navigation button:active {
|
||||
border-color: rgb(112, 12, 73);
|
||||
background-color: rgb(209, 46, 142);
|
||||
background-image: -webkit-gradient(
|
||||
linear, left top, left bottom,
|
||||
from(rgb(252, 124, 202)),
|
||||
color-stop(0.5, rgb(232, 93, 178)),
|
||||
color-stop(0.5, rgb(209, 46, 142)),
|
||||
to(rgb(255, 0, 156))
|
||||
);
|
||||
background-image: -moz-linear-gradient(
|
||||
to bottom,
|
||||
rgb(252, 124, 202),
|
||||
rgb(232, 93, 178) 50%,
|
||||
rgb(209, 46, 142) 50%,
|
||||
rgb(255, 0, 156)
|
||||
);
|
||||
background-image: -webkit-linear-gradient(
|
||||
to bottom,
|
||||
rgb(252, 124, 202),
|
||||
rgb(232, 93, 178) 50%,
|
||||
rgb(209, 46, 142) 50%,
|
||||
rgb(255, 0, 156)
|
||||
);
|
||||
background-image: linear-gradient(
|
||||
to bottom,
|
||||
rgb(252, 124, 202),
|
||||
rgb(232, 93, 178) 50%,
|
||||
rgb(209, 46, 142) 50%,
|
||||
rgb(255, 0, 156)
|
||||
);
|
||||
}
|
||||
|
||||
.annotator-editor a.annotator-save::after {
|
||||
background-position: 0 -120px;
|
||||
}
|
||||
|
||||
.annotator-editor a.annotator-save:hover::after,
|
||||
.annotator-editor a.annotator-save:focus::after,
|
||||
.annotator-editor a.annotator-save.annotator-focus::after {
|
||||
margin-top: -8px;
|
||||
background-position: 0 -135px;
|
||||
}
|
||||
|
||||
.annotator-editor .annotator-widget::after {
|
||||
background-position: 0 -30px;
|
||||
}
|
||||
|
||||
.annotator-editor.annotator-invert-y .annotator-widget .annotator-controls {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.annotator-editor.annotator-invert-y .annotator-widget::after {
|
||||
background-position: 0 -45px;
|
||||
height: 11px;
|
||||
}
|
||||
|
||||
.annotator-resize {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background-position: 2px -150px;
|
||||
}
|
||||
|
||||
.annotator-invert-x .annotator-resize {
|
||||
right: auto;
|
||||
left: 0;
|
||||
background-position: 0 -195px;
|
||||
}
|
||||
|
||||
.annotator-invert-y .annotator-resize {
|
||||
top: auto;
|
||||
bottom: 0;
|
||||
background-position: 2px -165px;
|
||||
}
|
||||
|
||||
.annotator-invert-y.annotator-invert-x .annotator-resize {
|
||||
background-position: 0 -180px;
|
||||
}
|
||||
|
||||
/* Annotator Notification
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-notice {
|
||||
color: #fff;
|
||||
position: absolute;
|
||||
position: fixed;
|
||||
top: -54px;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
font-size: 14px;
|
||||
line-height: 50px;
|
||||
text-align: center;
|
||||
background: black;
|
||||
background: rgba(0, 0, 0, 0.9);
|
||||
border-bottom: 4px solid #d4d4d4;
|
||||
-webkit-transition: top 0.4s ease-out;
|
||||
-moz-transition: top 0.4s ease-out;
|
||||
-o-transition: top 0.4s ease-out;
|
||||
transition: top 0.4s ease-out;
|
||||
}
|
||||
|
||||
.ie6 .annotator-notice {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.annotator-notice-success {
|
||||
border-color: #3665f9;
|
||||
}
|
||||
|
||||
.annotator-notice-error {
|
||||
border-color: #ff7e00;
|
||||
}
|
||||
|
||||
.annotator-notice p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.annotator-notice a {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.annotator-notice-show {
|
||||
top: 0;
|
||||
}
|
||||
|
||||
/* Annotator Tags Plugin
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-tags {
|
||||
margin-bottom: -2px;
|
||||
}
|
||||
|
||||
.annotator-tags .annotator-tag {
|
||||
display: inline-block;
|
||||
padding: 0 8px;
|
||||
margin-bottom: 2px;
|
||||
line-height: 1.6;
|
||||
font-weight: bold;
|
||||
background-color: rgb(230, 230, 230);
|
||||
-webkit-border-radius: 8px;
|
||||
-moz-border-radius: 8px;
|
||||
-o-border-radius: 8px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
/* Annotator Filter Plugin
|
||||
-------------------------------------------------------------------- */
|
||||
|
||||
.annotator-filter {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
text-align: left;
|
||||
line-height: 0;
|
||||
border: none;
|
||||
border-bottom: 1px solid #878787;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
-webkit-border-radius: 0;
|
||||
-moz-border-radius: 0;
|
||||
-o-border-radius: 0;
|
||||
border-radius: 0;
|
||||
-webkit-box-shadow:
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.3);
|
||||
-moz-box-shadow:
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.3);
|
||||
-o-box-shadow:
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.3);
|
||||
box-shadow:
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.annotator-filter strong {
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
color: #3c3c3c;
|
||||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
position: relative;
|
||||
top: -9px;
|
||||
}
|
||||
|
||||
|
||||
.annotator-filter .annotator-filter-property,
|
||||
.annotator-filter .annotator-filter-navigation {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
line-height: 10px;
|
||||
padding: 2px 0;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-property label,
|
||||
.annotator-filter .annotator-filter-navigation button {
|
||||
text-align: left;
|
||||
display: block;
|
||||
float: left;
|
||||
line-height: 20px;
|
||||
-webkit-border-radius: 10px 0 0 10px;
|
||||
-moz-border-radius: 10px 0 0 10px;
|
||||
-o-border-radius: 10px 0 0 10px;
|
||||
border-radius: 10px 0 0 10px;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-property label {
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-property input {
|
||||
display: block;
|
||||
float: right;
|
||||
-webkit-appearance: none;
|
||||
background-color: #fff;
|
||||
border: 1px solid #878787;
|
||||
border-left: none;
|
||||
padding: 2px 4px;
|
||||
line-height: 16px;
|
||||
min-height: 16px;
|
||||
font-size: 12px;
|
||||
width: 150px;
|
||||
color: #333;
|
||||
background-color: #f8f8f8;
|
||||
-webkit-border-radius: 0 10px 10px 0;
|
||||
-moz-border-radius: 0 10px 10px 0;
|
||||
-o-border-radius: 0 10px 10px 0;
|
||||
border-radius: 0 10px 10px 0;
|
||||
-webkit-box-shadow:
|
||||
inset 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
-moz-box-shadow:
|
||||
inset 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
-o-box-shadow:
|
||||
inset 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
box-shadow:
|
||||
inset 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-property input:focus {
|
||||
outline: none;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-clear {
|
||||
position: absolute;
|
||||
right: 3px;
|
||||
top: 6px;
|
||||
border: none;
|
||||
text-indent: -900em;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
background-position: 0 -90px;
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-clear:hover,
|
||||
.annotator-filter .annotator-filter-clear:focus {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-clear:active {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation button {
|
||||
border: 1px solid rgb(162, 162, 162);
|
||||
padding: 0;
|
||||
text-indent: -900px;
|
||||
width: 20px;
|
||||
min-height: 22px;
|
||||
-webkit-box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
-moz-box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
-o-box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
box-shadow:
|
||||
inset 0 0 5px rgba(255, 255, 255, 0.2),
|
||||
inset 0 0 1px rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation button,
|
||||
.annotator-filter .annotator-filter-navigation button:hover,
|
||||
.annotator-filter .annotator-filter-navigation button:focus {
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation button::after {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
content: "";
|
||||
display: block;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
background-position: 0 -210px;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation button:hover::after {
|
||||
background-position: 0 -225px;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation .annotator-filter-next {
|
||||
-webkit-border-radius: 0 10px 10px 0;
|
||||
-moz-border-radius: 0 10px 10px 0;
|
||||
-o-border-radius: 0 10px 10px 0;
|
||||
border-radius: 0 10px 10px 0;
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation .annotator-filter-next::after {
|
||||
left: auto;
|
||||
right: 7px;
|
||||
background-position: 0 -240px;
|
||||
}
|
||||
|
||||
.annotator-filter .annotator-filter-navigation .annotator-filter-next:hover::after {
|
||||
background-position: 0 -255px;
|
||||
}
|
||||
|
||||
.annotator-hl-active {
|
||||
background: rgba(255, 255, 10, 0.8);
|
||||
}
|
||||
|
||||
.annotator-hl-filtered {
|
||||
background-color: transparent;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7 KiB |
|
@ -1,595 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var Annotator, g, _Annotator, _ref,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
_Annotator = this.Annotator;
|
||||
|
||||
Annotator = (function(_super) {
|
||||
__extends(Annotator, _super);
|
||||
|
||||
Annotator.prototype.events = {
|
||||
".annotator-adder button click": "onAdderClick",
|
||||
".annotator-adder button mousedown": "onAdderMousedown",
|
||||
".annotator-hl mouseover": "onHighlightMouseover",
|
||||
".annotator-hl mouseout": "startViewerHideTimer"
|
||||
};
|
||||
|
||||
Annotator.prototype.html = {
|
||||
adder: '<div class="annotator-adder"><button>' + _t('Annotate') + '</button></div>',
|
||||
wrapper: '<div class="annotator-wrapper"></div>'
|
||||
};
|
||||
|
||||
Annotator.prototype.options = {
|
||||
readOnly: false
|
||||
};
|
||||
|
||||
Annotator.prototype.plugins = {};
|
||||
|
||||
Annotator.prototype.editor = null;
|
||||
|
||||
Annotator.prototype.viewer = null;
|
||||
|
||||
Annotator.prototype.selectedRanges = null;
|
||||
|
||||
Annotator.prototype.mouseIsDown = false;
|
||||
|
||||
Annotator.prototype.ignoreMouseup = false;
|
||||
|
||||
Annotator.prototype.viewerHideTimer = null;
|
||||
|
||||
function Annotator(element, options) {
|
||||
this.onDeleteAnnotation = __bind(this.onDeleteAnnotation, this);
|
||||
this.onEditAnnotation = __bind(this.onEditAnnotation, this);
|
||||
this.onAdderClick = __bind(this.onAdderClick, this);
|
||||
this.onAdderMousedown = __bind(this.onAdderMousedown, this);
|
||||
this.onHighlightMouseover = __bind(this.onHighlightMouseover, this);
|
||||
this.checkForEndSelection = __bind(this.checkForEndSelection, this);
|
||||
this.checkForStartSelection = __bind(this.checkForStartSelection, this);
|
||||
this.clearViewerHideTimer = __bind(this.clearViewerHideTimer, this);
|
||||
this.startViewerHideTimer = __bind(this.startViewerHideTimer, this);
|
||||
this.showViewer = __bind(this.showViewer, this);
|
||||
this.onEditorSubmit = __bind(this.onEditorSubmit, this);
|
||||
this.onEditorHide = __bind(this.onEditorHide, this);
|
||||
this.showEditor = __bind(this.showEditor, this);
|
||||
Annotator.__super__.constructor.apply(this, arguments);
|
||||
this.plugins = {};
|
||||
this.document = element.ownerDocument || document;
|
||||
if (!Annotator.supported()) {
|
||||
return this;
|
||||
}
|
||||
if (!this.options.readOnly) {
|
||||
this._setupDocumentEvents();
|
||||
}
|
||||
this._setupWrapper()._setupViewer()._setupEditor();
|
||||
this._setupDynamicStyle();
|
||||
this.adder = $(this.html.adder).appendTo(this.wrapper).hide();
|
||||
Annotator._instances.push(this);
|
||||
}
|
||||
|
||||
Annotator.prototype._setupWrapper = function() {
|
||||
this.wrapper = $(this.html.wrapper);
|
||||
this.element.find('script').remove();
|
||||
this.element.wrapInner(this.wrapper);
|
||||
this.wrapper = this.element.find('.annotator-wrapper');
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype._setupViewer = function() {
|
||||
var _this = this;
|
||||
this.viewer = new Annotator.Viewer({
|
||||
readOnly: this.options.readOnly
|
||||
});
|
||||
this.viewer.hide().on("edit", this.onEditAnnotation).on("delete", this.onDeleteAnnotation).addField({
|
||||
load: function(field, annotation) {
|
||||
if (annotation.text) {
|
||||
$(field).html(Util.escape(annotation.text));
|
||||
} else {
|
||||
$(field).html("<i>" + (_t('No Comment')) + "</i>");
|
||||
}
|
||||
return _this.publish('annotationViewerTextField', [field, annotation]);
|
||||
}
|
||||
}).element.appendTo(this.wrapper).bind({
|
||||
"mouseover": this.clearViewerHideTimer,
|
||||
"mouseout": this.startViewerHideTimer
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype._setupEditor = function() {
|
||||
this.editor = new Annotator.Editor();
|
||||
this.editor.hide().on('hide', this.onEditorHide).on('save', this.onEditorSubmit).addField({
|
||||
type: 'textarea',
|
||||
label: _t('Comments') + '\u2026',
|
||||
load: function(field, annotation) {
|
||||
return $(field).find('textarea').val(annotation.text || '');
|
||||
},
|
||||
submit: function(field, annotation) {
|
||||
return annotation.text = $(field).find('textarea').val();
|
||||
}
|
||||
});
|
||||
this.editor.element.appendTo(this.wrapper);
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype._setupDocumentEvents = function() {
|
||||
$(this.document).bind({
|
||||
"mouseup": this.checkForEndSelection,
|
||||
"mousedown": this.checkForStartSelection
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype._setupDynamicStyle = function() {
|
||||
var max, sel, style, x;
|
||||
style = $('#annotator-dynamic-style');
|
||||
if (!style.length) {
|
||||
style = $('<style id="annotator-dynamic-style"></style>').appendTo(this.document.head);
|
||||
}
|
||||
sel = '*' + ((function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = ['adder', 'outer', 'notice', 'filter'];
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
x = _ref[_i];
|
||||
_results.push(":not(.annotator-" + x + ")");
|
||||
}
|
||||
return _results;
|
||||
})()).join('');
|
||||
max = Util.maxZIndex($(this.document.body).find(sel));
|
||||
max = Math.max(max, 1000);
|
||||
style.text([".annotator-adder, .annotator-outer, .annotator-notice {", " z-index: " + (max + 20) + ";", "}", ".annotator-filter {", " z-index: " + (max + 10) + ";", "}"].join("\n"));
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype.destroy = function() {
|
||||
var idx, name, plugin, _ref;
|
||||
$(this.document).unbind({
|
||||
"mouseup": this.checkForEndSelection,
|
||||
"mousedown": this.checkForStartSelection
|
||||
});
|
||||
$('#annotator-dynamic-style').remove();
|
||||
this.adder.remove();
|
||||
this.viewer.destroy();
|
||||
this.editor.destroy();
|
||||
this.wrapper.find('.annotator-hl').each(function() {
|
||||
$(this).contents().insertBefore(this);
|
||||
return $(this).remove();
|
||||
});
|
||||
this.wrapper.contents().insertBefore(this.wrapper);
|
||||
this.wrapper.remove();
|
||||
this.element.data('annotator', null);
|
||||
_ref = this.plugins;
|
||||
for (name in _ref) {
|
||||
plugin = _ref[name];
|
||||
this.plugins[name].destroy();
|
||||
}
|
||||
this.removeEvents();
|
||||
idx = Annotator._instances.indexOf(this);
|
||||
if (idx !== -1) {
|
||||
return Annotator._instances.splice(idx, 1);
|
||||
}
|
||||
};
|
||||
|
||||
Annotator.prototype.getSelectedRanges = function() {
|
||||
var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _i, _len;
|
||||
selection = this.document.getSelection();
|
||||
ranges = [];
|
||||
rangesToIgnore = [];
|
||||
if (!selection.isCollapsed) {
|
||||
ranges = (function() {
|
||||
var _i, _ref, _results;
|
||||
_results = [];
|
||||
for (i = _i = 0, _ref = selection.rangeCount; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
|
||||
r = selection.getRangeAt(i);
|
||||
browserRange = new Range.BrowserRange(r);
|
||||
normedRange = browserRange.normalize().limit(this.wrapper[0]);
|
||||
if (normedRange === null) {
|
||||
rangesToIgnore.push(r);
|
||||
}
|
||||
_results.push(normedRange);
|
||||
}
|
||||
return _results;
|
||||
}).call(this);
|
||||
selection.removeAllRanges();
|
||||
}
|
||||
for (_i = 0, _len = rangesToIgnore.length; _i < _len; _i++) {
|
||||
r = rangesToIgnore[_i];
|
||||
selection.addRange(r);
|
||||
}
|
||||
return $.grep(ranges, function(range) {
|
||||
if (range) {
|
||||
selection.addRange(range.toRange());
|
||||
}
|
||||
return range;
|
||||
});
|
||||
};
|
||||
|
||||
Annotator.prototype.createAnnotation = function() {
|
||||
var annotation;
|
||||
annotation = {};
|
||||
this.publish('beforeAnnotationCreated', [annotation]);
|
||||
return annotation;
|
||||
};
|
||||
|
||||
Annotator.prototype.setupAnnotation = function(annotation) {
|
||||
var e, normed, normedRanges, r, root, _i, _j, _len, _len1, _ref;
|
||||
root = this.wrapper[0];
|
||||
annotation.ranges || (annotation.ranges = this.selectedRanges);
|
||||
normedRanges = [];
|
||||
_ref = annotation.ranges;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
r = _ref[_i];
|
||||
try {
|
||||
normedRanges.push(Range.sniff(r).normalize(root));
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
if (e instanceof Range.RangeError) {
|
||||
this.publish('rangeNormalizeFail', [annotation, r, e]);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
annotation.quote = [];
|
||||
annotation.ranges = [];
|
||||
annotation.highlights = [];
|
||||
for (_j = 0, _len1 = normedRanges.length; _j < _len1; _j++) {
|
||||
normed = normedRanges[_j];
|
||||
annotation.quote.push($.trim(normed.text()));
|
||||
annotation.ranges.push(normed.serialize(this.wrapper[0], '.annotator-hl'));
|
||||
$.merge(annotation.highlights, this.highlightRange(normed));
|
||||
}
|
||||
annotation.quote = annotation.quote.join(' / ');
|
||||
$(annotation.highlights).data('annotation', annotation);
|
||||
return annotation;
|
||||
};
|
||||
|
||||
Annotator.prototype.updateAnnotation = function(annotation) {
|
||||
this.publish('beforeAnnotationUpdated', [annotation]);
|
||||
this.publish('annotationUpdated', [annotation]);
|
||||
return annotation;
|
||||
};
|
||||
|
||||
Annotator.prototype.deleteAnnotation = function(annotation) {
|
||||
var child, h, _i, _len, _ref;
|
||||
if (annotation.highlights != null) {
|
||||
_ref = annotation.highlights;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
h = _ref[_i];
|
||||
if (!(h.parentNode != null)) {
|
||||
continue;
|
||||
}
|
||||
child = h.childNodes[0];
|
||||
$(h).replaceWith(h.childNodes);
|
||||
}
|
||||
}
|
||||
this.publish('annotationDeleted', [annotation]);
|
||||
return annotation;
|
||||
};
|
||||
|
||||
Annotator.prototype.loadAnnotations = function(annotations) {
|
||||
var clone, loader,
|
||||
_this = this;
|
||||
if (annotations == null) {
|
||||
annotations = [];
|
||||
}
|
||||
loader = function(annList) {
|
||||
var n, now, _i, _len;
|
||||
if (annList == null) {
|
||||
annList = [];
|
||||
}
|
||||
now = annList.splice(0, 10);
|
||||
for (_i = 0, _len = now.length; _i < _len; _i++) {
|
||||
n = now[_i];
|
||||
_this.setupAnnotation(n);
|
||||
}
|
||||
if (annList.length > 0) {
|
||||
return setTimeout((function() {
|
||||
return loader(annList);
|
||||
}), 10);
|
||||
} else {
|
||||
return _this.publish('annotationsLoaded', [clone]);
|
||||
}
|
||||
};
|
||||
clone = annotations.slice();
|
||||
if (annotations.length) {
|
||||
loader(annotations);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype.dumpAnnotations = function() {
|
||||
if (this.plugins['Store']) {
|
||||
return this.plugins['Store'].dumpAnnotations();
|
||||
} else {
|
||||
console.warn(_t("Can't dump annotations without Store plugin."));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Annotator.prototype.highlightRange = function(normedRange, cssClass) {
|
||||
var hl, node, white, _i, _len, _ref, _results;
|
||||
if (cssClass == null) {
|
||||
cssClass = 'annotator-hl';
|
||||
}
|
||||
white = /^\s*$/;
|
||||
hl = $("<span class='" + cssClass + "'></span>");
|
||||
_ref = normedRange.textNodes();
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
node = _ref[_i];
|
||||
if (!white.test(node.nodeValue)) {
|
||||
_results.push($(node).wrapAll(hl).parent().show()[0]);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Annotator.prototype.highlightRanges = function(normedRanges, cssClass) {
|
||||
var highlights, r, _i, _len;
|
||||
if (cssClass == null) {
|
||||
cssClass = 'annotator-hl';
|
||||
}
|
||||
highlights = [];
|
||||
for (_i = 0, _len = normedRanges.length; _i < _len; _i++) {
|
||||
r = normedRanges[_i];
|
||||
$.merge(highlights, this.highlightRange(r, cssClass));
|
||||
}
|
||||
return highlights;
|
||||
};
|
||||
|
||||
Annotator.prototype.addPlugin = function(name, options) {
|
||||
var klass, _base;
|
||||
if (this.plugins[name]) {
|
||||
console.error(_t("You cannot have more than one instance of any plugin."));
|
||||
} else {
|
||||
klass = Annotator.Plugin[name];
|
||||
if (typeof klass === 'function') {
|
||||
this.plugins[name] = new klass(this.element[0], options);
|
||||
this.plugins[name].annotator = this;
|
||||
if (typeof (_base = this.plugins[name]).pluginInit === "function") {
|
||||
_base.pluginInit();
|
||||
}
|
||||
} else {
|
||||
console.error(_t("Could not load ") + name + _t(" plugin. Have you included the appropriate <script> tag?"));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype.showEditor = function(annotation, location) {
|
||||
this.editor.element.css(location);
|
||||
this.editor.load(annotation);
|
||||
this.publish('annotationEditorShown', [this.editor, annotation]);
|
||||
return this;
|
||||
};
|
||||
|
||||
Annotator.prototype.onEditorHide = function() {
|
||||
this.publish('annotationEditorHidden', [this.editor]);
|
||||
return this.ignoreMouseup = false;
|
||||
};
|
||||
|
||||
Annotator.prototype.onEditorSubmit = function(annotation) {
|
||||
return this.publish('annotationEditorSubmit', [this.editor, annotation]);
|
||||
};
|
||||
|
||||
Annotator.prototype.showViewer = function(annotations, location) {
|
||||
this.viewer.element.css(location);
|
||||
this.viewer.load(annotations);
|
||||
return this.publish('annotationViewerShown', [this.viewer, annotations]);
|
||||
};
|
||||
|
||||
Annotator.prototype.startViewerHideTimer = function() {
|
||||
if (!this.viewerHideTimer) {
|
||||
return this.viewerHideTimer = setTimeout(this.viewer.hide, 250);
|
||||
}
|
||||
};
|
||||
|
||||
Annotator.prototype.clearViewerHideTimer = function() {
|
||||
clearTimeout(this.viewerHideTimer);
|
||||
return this.viewerHideTimer = false;
|
||||
};
|
||||
|
||||
Annotator.prototype.checkForStartSelection = function(event) {
|
||||
if (!(event && this.isAnnotator(event.target))) {
|
||||
this.startViewerHideTimer();
|
||||
}
|
||||
return this.mouseIsDown = true;
|
||||
};
|
||||
|
||||
Annotator.prototype.checkForEndSelection = function(event) {
|
||||
var container, range, _i, _len, _ref;
|
||||
this.mouseIsDown = false;
|
||||
if (this.ignoreMouseup) {
|
||||
return;
|
||||
}
|
||||
this.selectedRanges = this.getSelectedRanges();
|
||||
_ref = this.selectedRanges;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
range = _ref[_i];
|
||||
container = range.commonAncestor;
|
||||
if ($(container).hasClass('annotator-hl')) {
|
||||
container = $(container).parents('[class!=annotator-hl]')[0];
|
||||
}
|
||||
if (this.isAnnotator(container)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event && this.selectedRanges.length) {
|
||||
return this.adder.css(Util.mousePosition(event, this.wrapper[0])).show();
|
||||
} else {
|
||||
return this.adder.hide();
|
||||
}
|
||||
};
|
||||
|
||||
Annotator.prototype.isAnnotator = function(element) {
|
||||
return !!$(element).parents().andSelf().filter('[class^=annotator-]').not(this.wrapper).length;
|
||||
};
|
||||
|
||||
Annotator.prototype.onHighlightMouseover = function(event) {
|
||||
var annotations;
|
||||
this.clearViewerHideTimer();
|
||||
if (this.mouseIsDown || this.viewer.isShown()) {
|
||||
return false;
|
||||
}
|
||||
annotations = $(event.target).parents('.annotator-hl').andSelf().map(function() {
|
||||
return $(this).data("annotation");
|
||||
});
|
||||
return this.showViewer($.makeArray(annotations), Util.mousePosition(event, this.wrapper[0]));
|
||||
};
|
||||
|
||||
Annotator.prototype.onAdderMousedown = function(event) {
|
||||
if (event != null) {
|
||||
event.preventDefault();
|
||||
}
|
||||
return this.ignoreMouseup = true;
|
||||
};
|
||||
|
||||
Annotator.prototype.onAdderClick = function(event) {
|
||||
var annotation, cancel, cleanup, position, save,
|
||||
_this = this;
|
||||
if (event != null) {
|
||||
event.preventDefault();
|
||||
}
|
||||
position = this.adder.position();
|
||||
this.adder.hide();
|
||||
annotation = this.setupAnnotation(this.createAnnotation());
|
||||
$(annotation.highlights).addClass('annotator-hl-temporary');
|
||||
save = function() {
|
||||
cleanup();
|
||||
$(annotation.highlights).removeClass('annotator-hl-temporary');
|
||||
return _this.publish('annotationCreated', [annotation]);
|
||||
};
|
||||
cancel = function() {
|
||||
cleanup();
|
||||
return _this.deleteAnnotation(annotation);
|
||||
};
|
||||
cleanup = function() {
|
||||
_this.unsubscribe('annotationEditorHidden', cancel);
|
||||
return _this.unsubscribe('annotationEditorSubmit', save);
|
||||
};
|
||||
this.subscribe('annotationEditorHidden', cancel);
|
||||
this.subscribe('annotationEditorSubmit', save);
|
||||
return this.showEditor(annotation, position);
|
||||
};
|
||||
|
||||
Annotator.prototype.onEditAnnotation = function(annotation) {
|
||||
var cleanup, offset, update,
|
||||
_this = this;
|
||||
offset = this.viewer.element.position();
|
||||
update = function() {
|
||||
cleanup();
|
||||
return _this.updateAnnotation(annotation);
|
||||
};
|
||||
cleanup = function() {
|
||||
_this.unsubscribe('annotationEditorHidden', cleanup);
|
||||
return _this.unsubscribe('annotationEditorSubmit', update);
|
||||
};
|
||||
this.subscribe('annotationEditorHidden', cleanup);
|
||||
this.subscribe('annotationEditorSubmit', update);
|
||||
this.viewer.hide();
|
||||
return this.showEditor(annotation, offset);
|
||||
};
|
||||
|
||||
Annotator.prototype.onDeleteAnnotation = function(annotation) {
|
||||
this.viewer.hide();
|
||||
return this.deleteAnnotation(annotation);
|
||||
};
|
||||
|
||||
return Annotator;
|
||||
|
||||
})(Delegator);
|
||||
|
||||
Annotator.Plugin = (function(_super) {
|
||||
__extends(Plugin, _super);
|
||||
|
||||
function Plugin(element, options) {
|
||||
Plugin.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Plugin.prototype.pluginInit = function() {};
|
||||
|
||||
Plugin.prototype.destroy = function() {
|
||||
return this.removeEvents();
|
||||
};
|
||||
|
||||
return Plugin;
|
||||
|
||||
})(Delegator);
|
||||
|
||||
g = Util.getGlobal();
|
||||
|
||||
if (((_ref = g.document) != null ? _ref.evaluate : void 0) == null) {
|
||||
$.getScript('http://assets.annotateit.org/vendor/xpath.min.js');
|
||||
}
|
||||
|
||||
if (g.getSelection == null) {
|
||||
$.getScript('http://assets.annotateit.org/vendor/ierange.min.js');
|
||||
}
|
||||
|
||||
if (g.JSON == null) {
|
||||
$.getScript('http://assets.annotateit.org/vendor/json2.min.js');
|
||||
}
|
||||
|
||||
if (g.Node == null) {
|
||||
g.Node = {
|
||||
ELEMENT_NODE: 1,
|
||||
ATTRIBUTE_NODE: 2,
|
||||
TEXT_NODE: 3,
|
||||
CDATA_SECTION_NODE: 4,
|
||||
ENTITY_REFERENCE_NODE: 5,
|
||||
ENTITY_NODE: 6,
|
||||
PROCESSING_INSTRUCTION_NODE: 7,
|
||||
COMMENT_NODE: 8,
|
||||
DOCUMENT_NODE: 9,
|
||||
DOCUMENT_TYPE_NODE: 10,
|
||||
DOCUMENT_FRAGMENT_NODE: 11,
|
||||
NOTATION_NODE: 12
|
||||
};
|
||||
}
|
||||
|
||||
Annotator.$ = $;
|
||||
|
||||
Annotator.Delegator = Delegator;
|
||||
|
||||
Annotator.Range = Range;
|
||||
|
||||
Annotator.Util = Util;
|
||||
|
||||
Annotator._instances = [];
|
||||
|
||||
Annotator._t = _t;
|
||||
|
||||
Annotator.supported = function() {
|
||||
return (function() {
|
||||
return !!this.getSelection;
|
||||
})();
|
||||
};
|
||||
|
||||
Annotator.noConflict = function() {
|
||||
Util.getGlobal().Annotator = _Annotator;
|
||||
return this;
|
||||
};
|
||||
|
||||
$.fn.annotator = function(options) {
|
||||
var args;
|
||||
args = Array.prototype.slice.call(arguments, 1);
|
||||
return this.each(function() {
|
||||
var instance;
|
||||
instance = $.data(this, 'annotator');
|
||||
if (instance) {
|
||||
return options && instance[options].apply(instance, args);
|
||||
} else {
|
||||
instance = new Annotator(this, options);
|
||||
return $.data(this, 'annotator', instance);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.Annotator = Annotator;
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=annotator.map
|
||||
*/
|
File diff suppressed because one or more lines are too long
|
@ -1,132 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var Delegator,
|
||||
__slice = [].slice,
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
Delegator = (function() {
|
||||
Delegator.prototype.events = {};
|
||||
|
||||
Delegator.prototype.options = {};
|
||||
|
||||
Delegator.prototype.element = null;
|
||||
|
||||
function Delegator(element, options) {
|
||||
this.options = $.extend(true, {}, this.options, options);
|
||||
this.element = $(element);
|
||||
this._closures = {};
|
||||
this.on = this.subscribe;
|
||||
this.addEvents();
|
||||
}
|
||||
|
||||
Delegator.prototype.addEvents = function() {
|
||||
var event, _i, _len, _ref, _results;
|
||||
_ref = Delegator._parseEvents(this.events);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
event = _ref[_i];
|
||||
_results.push(this._addEvent(event.selector, event.event, event.functionName));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Delegator.prototype.removeEvents = function() {
|
||||
var event, _i, _len, _ref, _results;
|
||||
_ref = Delegator._parseEvents(this.events);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
event = _ref[_i];
|
||||
_results.push(this._removeEvent(event.selector, event.event, event.functionName));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Delegator.prototype._addEvent = function(selector, event, functionName) {
|
||||
var closure,
|
||||
_this = this;
|
||||
closure = function() {
|
||||
return _this[functionName].apply(_this, arguments);
|
||||
};
|
||||
if (selector === '' && Delegator._isCustomEvent(event)) {
|
||||
this.subscribe(event, closure);
|
||||
} else {
|
||||
this.element.delegate(selector, event, closure);
|
||||
}
|
||||
this._closures["" + selector + "/" + event + "/" + functionName] = closure;
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype._removeEvent = function(selector, event, functionName) {
|
||||
var closure;
|
||||
closure = this._closures["" + selector + "/" + event + "/" + functionName];
|
||||
if (selector === '' && Delegator._isCustomEvent(event)) {
|
||||
this.unsubscribe(event, closure);
|
||||
} else {
|
||||
this.element.undelegate(selector, event, closure);
|
||||
}
|
||||
delete this._closures["" + selector + "/" + event + "/" + functionName];
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype.publish = function() {
|
||||
this.element.triggerHandler.apply(this.element, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype.subscribe = function(event, callback) {
|
||||
var closure;
|
||||
closure = function() {
|
||||
return callback.apply(this, [].slice.call(arguments, 1));
|
||||
};
|
||||
closure.guid = callback.guid = ($.guid += 1);
|
||||
this.element.bind(event, closure);
|
||||
return this;
|
||||
};
|
||||
|
||||
Delegator.prototype.unsubscribe = function() {
|
||||
this.element.unbind.apply(this.element, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
return Delegator;
|
||||
|
||||
})();
|
||||
|
||||
Delegator._parseEvents = function(eventsObj) {
|
||||
var event, events, functionName, sel, selector, _i, _ref;
|
||||
events = [];
|
||||
for (sel in eventsObj) {
|
||||
functionName = eventsObj[sel];
|
||||
_ref = sel.split(' '), selector = 2 <= _ref.length ? __slice.call(_ref, 0, _i = _ref.length - 1) : (_i = 0, []), event = _ref[_i++];
|
||||
events.push({
|
||||
selector: selector.join(' '),
|
||||
event: event,
|
||||
functionName: functionName
|
||||
});
|
||||
}
|
||||
return events;
|
||||
};
|
||||
|
||||
Delegator.natives = (function() {
|
||||
var key, specials, val;
|
||||
specials = (function() {
|
||||
var _ref, _results;
|
||||
_ref = jQuery.event.special;
|
||||
_results = [];
|
||||
for (key in _ref) {
|
||||
if (!__hasProp.call(_ref, key)) continue;
|
||||
val = _ref[key];
|
||||
_results.push(key);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return "blur focus focusin focusout load resize scroll unload click dblclick\nmousedown mouseup mousemove mouseover mouseout mouseenter mouseleave\nchange select submit keydown keypress keyup error".split(/[^a-z]+/).concat(specials);
|
||||
})();
|
||||
|
||||
Delegator._isCustomEvent = function(event) {
|
||||
event = event.split('.')[0];
|
||||
return $.inArray(event, Delegator.natives) === -1;
|
||||
};
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=class.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "class.js",
|
||||
"sourceRoot": "..",
|
||||
"sources": [
|
||||
"src/class.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAGA,IAAA,KAAA;GAAA;gCAAA;;AAAM,CAAN;CAGE,CAAA,CAAQ,GAAR;;CAAA,CAAA,CAGS,IAAT;;CAHA,EAMS,CANT,GAMA;;CAgBa,CAAA,CAAA,IAAA,YAAC;CACZ,CAA0B,CAAf,CAAX,EAAW,CAAX;CAAA,EACW,CAAX,GAAA;CADA,CAAA,CAKa,CAAb,KAAA;CALA,CAOA,CAAU,CAAV,KAPA;CAAA,GAQA,KAAA;CA/BF,EAsBa;;CAtBb,EA0DW,MAAX;CACE,OAAA,uBAAA;CAAA;CAAA;UAAA,iCAAA;wBAAA;CACE,CAA+B,EAA3B,CAAgB,GAApB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CAPC,UAQT;CA9KF,EAsKW;;CAtKX,EAkMa,MAAA,EAAb;CACE,CAAgC,EAAhC,CAAA,CAAe,CAAP,EAAR;CADW,UAEX;CApMF,EAkMa;;CAlMb;;CAHF;;AA4MA,CA5MA,EA4MyB,MAAhB,GAAT;CACI,KAAA,8CAAA;CAAA,CAAA,CAAS,GAAT;AACA,CAAA,MAAA,SAAA;mCAAA;CACE,CAAC,CAAyB,CAA1B,CAAuB,EAAA,sEAAvB;CAAA,GACA,EAAM;CAAM,CACA,CAAA,CAAA,EAAV,EAAA;CADU,CAEH,GAAP,CAAA;CAFU,CAGI,IAAd,MAAA;CAJF,KACA;CAFF,EADA;CAQA,KAAA,GAAO;CATc;;AAczB,CA1NA,EA0NuB,IAAvB,EAAS;CACP,KAAA,YAAA;CAAA,CAAA,MAAA;;CAAY;CAAA;UAAA,CAAA;;uBAAA;CAAA;CAAA;;CAAZ;CAKI,IAJJ,CAAA,EAAA,CAAA,sLAIG;CANkB;;AAqBvB,CA/OA,EA+O2B,EAAA,IAAlB,KAAT;CACE,CAAC,CAAS,EAAK;AACyB,CAAvC,CAAgB,GAAjB,EAAA,EAAA;CAFyB"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var fn, functions, _i, _j, _len, _len1,
|
||||
__slice = [].slice;
|
||||
|
||||
functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"];
|
||||
|
||||
if (typeof console !== "undefined" && console !== null) {
|
||||
if (console.group == null) {
|
||||
console.group = function(name) {
|
||||
return console.log("GROUP: ", name);
|
||||
};
|
||||
}
|
||||
if (console.groupCollapsed == null) {
|
||||
console.groupCollapsed = console.group;
|
||||
}
|
||||
for (_i = 0, _len = functions.length; _i < _len; _i++) {
|
||||
fn = functions[_i];
|
||||
if (console[fn] == null) {
|
||||
console[fn] = function() {
|
||||
return console.log(_t("Not implemented:") + (" console." + name));
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.console = {};
|
||||
for (_j = 0, _len1 = functions.length; _j < _len1; _j++) {
|
||||
fn = functions[_j];
|
||||
this.console[fn] = function() {};
|
||||
}
|
||||
this.console['error'] = function() {
|
||||
var args;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
return alert("ERROR: " + (args.join(', ')));
|
||||
};
|
||||
this.console['warn'] = function() {
|
||||
var args;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
return alert("WARNING: " + (args.join(', ')));
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=console.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "console.js",
|
||||
"sourceRoot": "..",
|
||||
"sources": [
|
||||
"src/console.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAEA,IAAA,8BAAA;GAAA,eAAA;;AAAA,CAAA,CACS,CADG,EAAA,CAAA,CAAA,CAAA,CAAZ,CAAY,CAAA,CAAA,CAAA,EAAA,CAAA;;AAOZ,CAAA,GAAG,8CAAH;CAEE,CAAA,EAAO,iBAAP;CACE,EAAgB,CAAhB,CAAA,EAAO,EAAU;CAAiB,CAAe,CAAvB,CAAA,GAAO,EAAP,IAAA;CAA1B,IAAgB;IADlB;CAIA,CAAA,EAAO,0BAAP;CACE,EAAyB,CAAzB,CAAA,EAAO,OAAP;IALF;AAQA,CAAA,MAAA,yCAAA;wBAAA;CACE,GAAA,eAAA;CACE,CAAQ,CAAM,GAAd,CAAQ,EAAM;CAAW,CAAI,CAAZ,CAAqC,GAA9B,IAA+B,IAAtC,GAAY;CAA7B,MAAc;MAFlB;CAAA,EAVF;EAAA,IAAA;CAcE,CAAA,CAAe,CAAX,GAAJ;AAEA,CAAA,MAAA,2CAAA;wBAAA;CACE,CAAa,CAAM,CAAnB,GAAa,EAAM;CADrB,EAFA;CAAA,CAKA,CAAwB,CAApB,GAAS,EAAW;CACtB,GAAA,IAAA;CAAA,GADuB,mDACvB;CAAO,EAAQ,CAAI,CAAnB,IAAO,EAAP;CANF,EAKwB;CALxB,CAQA,CAAuB,CAAnB,EAAS,CAAA,EAAU;CACrB,GAAA,IAAA;CAAA,GADsB,mDACtB;CAAO,EAAU,CAAI,CAArB,MAAA;CATF,EAQuB;EA7BzB"
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Editor = (function(_super) {
|
||||
__extends(Editor, _super);
|
||||
|
||||
Editor.prototype.events = {
|
||||
"form submit": "submit",
|
||||
".annotator-save click": "submit",
|
||||
".annotator-cancel click": "hide",
|
||||
".annotator-cancel mouseover": "onCancelButtonMouseover",
|
||||
"textarea keydown": "processKeypress"
|
||||
};
|
||||
|
||||
Editor.prototype.classes = {
|
||||
hide: 'annotator-hide',
|
||||
focus: 'annotator-focus'
|
||||
};
|
||||
|
||||
Editor.prototype.html = "<div class=\"annotator-outer annotator-editor\">\n <form class=\"annotator-widget\">\n <ul class=\"annotator-listing\"></ul>\n <div class=\"annotator-controls\">\n <a href=\"#cancel\" class=\"annotator-cancel\">" + _t('Cancel') + "</a>\n<a href=\"#save\" class=\"annotator-save annotator-focus\">" + _t('Save') + "</a>\n </div>\n </form>\n</div>";
|
||||
|
||||
Editor.prototype.options = {};
|
||||
|
||||
function Editor(options) {
|
||||
this.onCancelButtonMouseover = __bind(this.onCancelButtonMouseover, this);
|
||||
this.processKeypress = __bind(this.processKeypress, this);
|
||||
this.submit = __bind(this.submit, this);
|
||||
this.load = __bind(this.load, this);
|
||||
this.hide = __bind(this.hide, this);
|
||||
this.show = __bind(this.show, this);
|
||||
Editor.__super__.constructor.call(this, $(this.html)[0], options);
|
||||
this.fields = [];
|
||||
this.annotation = {};
|
||||
}
|
||||
|
||||
Editor.prototype.show = function(event) {
|
||||
Annotator.Util.preventEventDefault(event);
|
||||
this.element.removeClass(this.classes.hide);
|
||||
this.element.find('.annotator-save').addClass(this.classes.focus);
|
||||
this.checkOrientation();
|
||||
this.element.find(":input:first").focus();
|
||||
this.setupDraggables();
|
||||
return this.publish('show');
|
||||
};
|
||||
|
||||
Editor.prototype.hide = function(event) {
|
||||
Annotator.Util.preventEventDefault(event);
|
||||
this.element.addClass(this.classes.hide);
|
||||
return this.publish('hide');
|
||||
};
|
||||
|
||||
Editor.prototype.load = function(annotation) {
|
||||
var field, _i, _len, _ref;
|
||||
this.annotation = annotation;
|
||||
this.publish('load', [this.annotation]);
|
||||
_ref = this.fields;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
field = _ref[_i];
|
||||
field.load(field.element, this.annotation);
|
||||
}
|
||||
return this.show();
|
||||
};
|
||||
|
||||
Editor.prototype.submit = function(event) {
|
||||
var field, _i, _len, _ref;
|
||||
Annotator.Util.preventEventDefault(event);
|
||||
_ref = this.fields;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
field = _ref[_i];
|
||||
field.submit(field.element, this.annotation);
|
||||
}
|
||||
this.publish('save', [this.annotation]);
|
||||
return this.hide();
|
||||
};
|
||||
|
||||
Editor.prototype.addField = function(options) {
|
||||
var element, field, input;
|
||||
field = $.extend({
|
||||
id: 'annotator-field-' + Annotator.Util.uuid(),
|
||||
type: 'input',
|
||||
label: '',
|
||||
load: function() {},
|
||||
submit: function() {}
|
||||
}, options);
|
||||
input = null;
|
||||
element = $('<li class="annotator-item" />');
|
||||
field.element = element[0];
|
||||
switch (field.type) {
|
||||
case 'textarea':
|
||||
input = $('<textarea />');
|
||||
break;
|
||||
case 'input':
|
||||
case 'checkbox':
|
||||
input = $('<input />');
|
||||
break;
|
||||
case 'select':
|
||||
input = $('<select />');
|
||||
}
|
||||
element.append(input);
|
||||
input.attr({
|
||||
id: field.id,
|
||||
placeholder: field.label
|
||||
});
|
||||
if (field.type === 'checkbox') {
|
||||
input[0].type = 'checkbox';
|
||||
element.addClass('annotator-checkbox');
|
||||
element.append($('<label />', {
|
||||
"for": field.id,
|
||||
html: field.label
|
||||
}));
|
||||
}
|
||||
this.element.find('ul:first').append(element);
|
||||
this.fields.push(field);
|
||||
return field.element;
|
||||
};
|
||||
|
||||
Editor.prototype.checkOrientation = function() {
|
||||
var controls, list;
|
||||
Editor.__super__.checkOrientation.apply(this, arguments);
|
||||
list = this.element.find('ul');
|
||||
controls = this.element.find('.annotator-controls');
|
||||
if (this.element.hasClass(this.classes.invert.y)) {
|
||||
controls.insertBefore(list);
|
||||
} else if (controls.is(':first-child')) {
|
||||
controls.insertAfter(list);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Editor.prototype.processKeypress = function(event) {
|
||||
if (event.keyCode === 27) {
|
||||
return this.hide();
|
||||
} else if (event.keyCode === 13 && !event.shiftKey) {
|
||||
return this.submit();
|
||||
}
|
||||
};
|
||||
|
||||
Editor.prototype.onCancelButtonMouseover = function() {
|
||||
return this.element.find('.' + this.classes.focus).removeClass(this.classes.focus);
|
||||
};
|
||||
|
||||
Editor.prototype.setupDraggables = function() {
|
||||
var classes, controls, cornerItem, editor, mousedown, onMousedown, onMousemove, onMouseup, resize, textarea, throttle,
|
||||
_this = this;
|
||||
this.element.find('.annotator-resize').remove();
|
||||
if (this.element.hasClass(this.classes.invert.y)) {
|
||||
cornerItem = this.element.find('.annotator-item:last');
|
||||
} else {
|
||||
cornerItem = this.element.find('.annotator-item:first');
|
||||
}
|
||||
if (cornerItem) {
|
||||
$('<span class="annotator-resize"></span>').appendTo(cornerItem);
|
||||
}
|
||||
mousedown = null;
|
||||
classes = this.classes;
|
||||
editor = this.element;
|
||||
textarea = null;
|
||||
resize = editor.find('.annotator-resize');
|
||||
controls = editor.find('.annotator-controls');
|
||||
throttle = false;
|
||||
onMousedown = function(event) {
|
||||
if (event.target === this) {
|
||||
mousedown = {
|
||||
element: this,
|
||||
top: event.pageY,
|
||||
left: event.pageX
|
||||
};
|
||||
textarea = editor.find('textarea:first');
|
||||
$(window).bind({
|
||||
'mouseup.annotator-editor-resize': onMouseup,
|
||||
'mousemove.annotator-editor-resize': onMousemove
|
||||
});
|
||||
return event.preventDefault();
|
||||
}
|
||||
};
|
||||
onMouseup = function() {
|
||||
mousedown = null;
|
||||
return $(window).unbind('.annotator-editor-resize');
|
||||
};
|
||||
onMousemove = function(event) {
|
||||
var diff, directionX, directionY, height, width;
|
||||
if (mousedown && throttle === false) {
|
||||
diff = {
|
||||
top: event.pageY - mousedown.top,
|
||||
left: event.pageX - mousedown.left
|
||||
};
|
||||
if (mousedown.element === resize[0]) {
|
||||
height = textarea.outerHeight();
|
||||
width = textarea.outerWidth();
|
||||
directionX = editor.hasClass(classes.invert.x) ? -1 : 1;
|
||||
directionY = editor.hasClass(classes.invert.y) ? 1 : -1;
|
||||
textarea.height(height + (diff.top * directionY));
|
||||
textarea.width(width + (diff.left * directionX));
|
||||
if (textarea.outerHeight() !== height) {
|
||||
mousedown.top = event.pageY;
|
||||
}
|
||||
if (textarea.outerWidth() !== width) {
|
||||
mousedown.left = event.pageX;
|
||||
}
|
||||
} else if (mousedown.element === controls[0]) {
|
||||
editor.css({
|
||||
top: parseInt(editor.css('top'), 10) + diff.top,
|
||||
left: parseInt(editor.css('left'), 10) + diff.left
|
||||
});
|
||||
mousedown.top = event.pageY;
|
||||
mousedown.left = event.pageX;
|
||||
}
|
||||
throttle = true;
|
||||
return setTimeout(function() {
|
||||
return throttle = false;
|
||||
}, 1000 / 60);
|
||||
}
|
||||
};
|
||||
resize.bind('mousedown', onMousedown);
|
||||
return controls.bind('mousedown', onMousedown);
|
||||
};
|
||||
|
||||
return Editor;
|
||||
|
||||
})(Annotator.Widget);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=editor.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "editor.js",
|
||||
"sourceRoot": "..",
|
||||
"sources": [
|
||||
"src/editor.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AACA,IAAA;;kSAAA;;AAAM,CAAN,QAAe;CAGb;;CAAA,EACE,GADF;CACE,CAA+B,EAA/B,IAAA,KAAA;CAAA,CAC+B,EAA/B,IADA,eACA;CADA,CAE+B,EAA/B,EAFA,mBAEA;CAFA,CAG+B,EAA/B,qBAHA,IAGA;CAHA,CAI+B,EAA/B,aAJA,CAIA;CALF,GAAA;;CAAA,EASE,IADF;CACE,CAAO,EAAP,YAAA;CAAA,CACO,EAAP,CAAA,YADA;CATF,GAAA;;CAAA,CAkB6D,CALvD,CAAN,EAMyE,EADZ,6BAlB7D,8BAaM,8JAAA;;CAbN,CAAA,CAyBS,IAAT;;CAsBa,CAAA,CAAA,IAAA,SAAC;CACZ,wEAAA;CAAA,wDAAA;CAAA,sCAAA;CAAA,kCAAA;CAAA,kCAAA;CAAA,kCAAA;CAAA,CAAmB,EAAnB,GAAA,iCAAM;CAAN,CAAA,CAEU,CAAV,EAAA;CAFA,CAAA,CAGc,CAAd,MAAA;CAnDF,EA+Ca;;CA/Cb,EAqEM,CAAN,CAAM,IAAC;CACL,GAAA,CAAA,IAAS,UAAT;CAAA,GAEA,GAAQ,IAAR;CAFA,GAGA,CAAA,EAAQ,CAAR,SAAA;CAHA,GAMA,YAAA;CANA,GASA,CAAA,EAAQ,OAAR;CATA,GAWA,WAAA;CAEK,GAAD,EAAJ,CAAA,IAAA;CAnFF,EAqEM;;CArEN,EAqGM,CAAN,CAAM,IAAC;CACL,GAAA,CAAA,IAAS,UAAT;CAAA,GAEA,GAAQ,CAAR;CACK,G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AAqB,CAhB7B,CAgBQ,CAA8B,CAArB,CAhBjB;CAiBE,EAAA,GAAM,IAAN;CAAW,CACH,CAAN,CAA6C,CAA9B,CAAM,EAAf,IAAN;CADS,CAEH,CAAS,CAAf,EAAqB,EAAf,IAAN;CAFF,WAAA;CAAA,EAKA,EAAsB,IAAb,CAAT;CALA,EAMiB,CAAjB,CAAsB,IAAb,CAAT;UA5BF;CAAA,EA8BW,CA9BX,IA8BA;CACW,EAAA,MAAA,CAAX,KAAA;CAAW,EACE,KAAX,SAAA;CADF,CAEE,CAAK,CAAL,KAFS;QAjCD;CAxCd,IAwCc;CAxCd,CA6E2B,EAA3B,EAAM,KAAN;CACS,CAAkB,EAA3B,IAAQ,GAAR;CAzXF,EA0SiB;;CA1SjB;;CAH6B,QAAS"
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var fixtureElem, fixtureMemo;
|
||||
|
||||
this.MockSelection = (function() {
|
||||
MockSelection.prototype.rangeCount = 1;
|
||||
|
||||
MockSelection.prototype.isCollapsed = false;
|
||||
|
||||
function MockSelection(fixElem, data) {
|
||||
this.root = fixElem;
|
||||
this.rootXPath = Util.xpathFromNode($(fixElem))[0];
|
||||
this.startContainer = this.resolvePath(data[0]);
|
||||
this.startOffset = data[1];
|
||||
this.endContainer = this.resolvePath(data[2]);
|
||||
this.endOffset = data[3];
|
||||
this.expectation = data[4];
|
||||
this.description = data[5];
|
||||
this.commonAncestor = this.startContainer;
|
||||
while (!Util.contains(this.commonAncestor, this.endContainer)) {
|
||||
this.commonAncestor = this.commonAncestor.parentNode;
|
||||
}
|
||||
this.commonAncestorXPath = Util.xpathFromNode($(this.commonAncestor))[0];
|
||||
}
|
||||
|
||||
MockSelection.prototype.getRangeAt = function() {
|
||||
return {
|
||||
startContainer: this.startContainer,
|
||||
startOffset: this.startOffset,
|
||||
endContainer: this.endContainer,
|
||||
endOffset: this.endOffset,
|
||||
commonAncestorContainer: this.commonAncestor
|
||||
};
|
||||
};
|
||||
|
||||
MockSelection.prototype.resolvePath = function(path) {
|
||||
if (typeof path === "number") {
|
||||
return Util.getTextNodes($(this.root))[path];
|
||||
} else if (typeof path === "string") {
|
||||
return this.resolveXPath(this.rootXPath + path);
|
||||
}
|
||||
};
|
||||
|
||||
MockSelection.prototype.resolveXPath = function(xpath) {
|
||||
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
};
|
||||
|
||||
return MockSelection;
|
||||
|
||||
})();
|
||||
|
||||
this.textInNormedRange = function(range) {
|
||||
var textNodes;
|
||||
textNodes = Util.getTextNodes($(range.commonAncestor));
|
||||
textNodes = textNodes.slice(textNodes.index(range.start), +textNodes.index(range.end) + 1 || 9e9).get();
|
||||
return textNodes.reduce((function(acc, next) {
|
||||
return acc += next.nodeValue;
|
||||
}), "");
|
||||
};
|
||||
|
||||
this.DateToISO8601String = function(format, offset) {
|
||||
var d, date, offsetnum, secs, str, zeropad;
|
||||
if (format == null) {
|
||||
format = 6;
|
||||
}
|
||||
/*
|
||||
accepted values for the format [1-6]:
|
||||
1 Year:
|
||||
YYYY (eg 1997)
|
||||
2 Year and month:
|
||||
YYYY-MM (eg 1997-07)
|
||||
3 Complete date:
|
||||
YYYY-MM-DD (eg 1997-07-16)
|
||||
4 Complete date plus hours and minutes:
|
||||
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
|
||||
5 Complete date plus hours, minutes and seconds:
|
||||
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
|
||||
6 Complete date plus hours, minutes, seconds and a decimal
|
||||
fraction of a second
|
||||
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
|
||||
*/
|
||||
|
||||
if (!offset) {
|
||||
offset = 'Z';
|
||||
date = this;
|
||||
} else {
|
||||
d = offset.match(/([-+])([0-9]{2}):([0-9]{2})/);
|
||||
offsetnum = (Number(d[2]) * 60) + Number(d[3]);
|
||||
offsetnum *= d[1] === '-' ? -1 : 1;
|
||||
date = new Date(Number(Number(this) + (offsetnum * 60000)));
|
||||
}
|
||||
zeropad = function(num) {
|
||||
return (num < 10 ? '0' : '') + num;
|
||||
};
|
||||
str = "";
|
||||
str += date.getUTCFullYear();
|
||||
if (format > 1) {
|
||||
str += "-" + zeropad(date.getUTCMonth() + 1);
|
||||
}
|
||||
if (format > 2) {
|
||||
str += "-" + zeropad(date.getUTCDate());
|
||||
}
|
||||
if (format > 3) {
|
||||
str += "T" + zeropad(date.getUTCHours()) + ":" + zeropad(date.getUTCMinutes());
|
||||
}
|
||||
if (format > 5) {
|
||||
secs = Number(date.getUTCSeconds() + "." + (date.getUTCMilliseconds() < 100 ? '0' : '') + zeropad(date.getUTCMilliseconds()));
|
||||
str += ":" + zeropad(secs);
|
||||
} else if (format > 4) {
|
||||
str += ":" + zeropad(date.getUTCSeconds());
|
||||
}
|
||||
if (format > 3) {
|
||||
str += offset;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
fixtureElem = document.getElementById('fixtures');
|
||||
|
||||
fixtureMemo = {};
|
||||
|
||||
this.setFixtureElem = function(elem) {
|
||||
return fixtureElem = elem;
|
||||
};
|
||||
|
||||
this.fix = function() {
|
||||
return fixtureElem;
|
||||
};
|
||||
|
||||
this.getFixture = function(fname) {
|
||||
if (fixtureMemo[fname] == null) {
|
||||
fixtureMemo[fname] = $.ajax({
|
||||
url: "fixtures/" + fname + ".html",
|
||||
async: false
|
||||
}).responseText;
|
||||
}
|
||||
return fixtureMemo[fname];
|
||||
};
|
||||
|
||||
this.addFixture = function(fname) {
|
||||
return $(this.getFixture(fname)).appendTo(fixtureElem);
|
||||
};
|
||||
|
||||
this.clearFixtures = function() {
|
||||
return $(fixtureElem).empty();
|
||||
};
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=spec_helper.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file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;;AAEA,CAjGA,EAiGsB,CAAlB,KAAmB,KAAvB;CAAsB,EACN,MAAd,EAAA;CADoB;;AAGtB,CApGA,EAoGA,CAAI,KAAO;CAAA,QACT;CADS;;AAGX,CAvGA,EAuGkB,CAAd,CAAc,IAAC,CAAnB;CACE,CAAA,EAAO,sBAAP;CACE,EAAqB,CAArB,CAAY,MAAA;CAAgB,CACpB,CAAN,EAAM,CAAN,CAD0B,IACpB;CADoB,CAEnB,GAAP,CAAA;CACA,KAHmB,MAArB;IADF;CAMY,IAAA,IAAZ,EAAY;CAPI;;AASlB,CAhHA,EAgHkB,CAAd,CAAc,IAAC,CAAnB;CACE,GAAM,CAAJ,GAAF,CAAA,CAAE,CAAF;CADgB;;AAGlB,CAnHA,EAmHqB,CAAjB,KAAiB,IAArB;CACE,IAAA,IAAA,EAAA;CADmB"
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var Annotator,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator = Annotator || {};
|
||||
|
||||
Annotator.Notification = (function(_super) {
|
||||
__extends(Notification, _super);
|
||||
|
||||
Notification.prototype.events = {
|
||||
"click": "hide"
|
||||
};
|
||||
|
||||
Notification.prototype.options = {
|
||||
html: "<div class='annotator-notice'></div>",
|
||||
classes: {
|
||||
show: "annotator-notice-show",
|
||||
info: "annotator-notice-info",
|
||||
success: "annotator-notice-success",
|
||||
error: "annotator-notice-error"
|
||||
}
|
||||
};
|
||||
|
||||
function Notification(options) {
|
||||
this.hide = __bind(this.hide, this);
|
||||
this.show = __bind(this.show, this);
|
||||
Notification.__super__.constructor.call(this, $(this.options.html).appendTo(document.body)[0], options);
|
||||
}
|
||||
|
||||
Notification.prototype.show = function(message, status) {
|
||||
if (status == null) {
|
||||
status = Annotator.Notification.INFO;
|
||||
}
|
||||
$(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).html(Util.escape(message || ""));
|
||||
setTimeout(this.hide, 5000);
|
||||
return this;
|
||||
};
|
||||
|
||||
Notification.prototype.hide = function() {
|
||||
$(this.element).removeClass(this.options.classes.show);
|
||||
return this;
|
||||
};
|
||||
|
||||
return Notification;
|
||||
|
||||
})(Delegator);
|
||||
|
||||
Annotator.Notification.INFO = 'show';
|
||||
|
||||
Annotator.Notification.SUCCESS = 'success';
|
||||
|
||||
Annotator.Notification.ERROR = 'error';
|
||||
|
||||
$(function() {
|
||||
var notification;
|
||||
notification = new Annotator.Notification;
|
||||
Annotator.showNotification = notification.show;
|
||||
return Annotator.hideNotification = notification.hide;
|
||||
});
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=notification.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "notification.js",
|
||||
"sourceRoot": "..",
|
||||
"sources": [
|
||||
"src/notification.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAAA,IAAA,KAAA;GAAA;;kSAAA;;AAAA,CAAA,CAAA,CAAY,CAAa,KAAzB;;AAMM,CANN,QAMe;CAGb;;CAAA,EACE,GADF;CACE,CAAS,EAAT,EAAA,CAAA;CADF,GAAA;;CAAA,EAKE,IADF;CACE,CAAM,EAAN,kCAAA;CAAA,CAEE,EADF,GAAA;CACE,CAAS,EAAT,EAAA,iBAAA;CAAA,CACS,EAAT,EAAA,iBADA;CAAA,CAES,IAAT,CAAA,mBAFA;CAAA,CAGS,GAAT,CAAA,kBAHA;MAFF;CALF,GAAA;;CA0Ba,CAAA,CAAA,IAAA,eAAC;CACZ,kCAAA;CAAA,kCAAA;CAAA,CAAmD,EAAnD,GAAgB,CAAV,sCAAA;CA3BR,EA0Ba;;CA1Bb,CA6CgB,CAAV,CAAN,EAAM,CAAA,EAAC;;CAA0B,EAAV,GAAP,GAAgB,GAAa;MAC3C;CAAA,CAGQ,EAHR,EAE6B,CAF7B,CAAA;CAAA,CAKsB,EAAtB,MAAA;CANI,UAOJ;CApDF,EA6CM;;CA7CN,EA8DM,CAAN,KAAM;CACJ,GAAA,GAAA,IAAA;CADI,UAEJ;CAhEF,EA8DM;;CA9DN;;CAHmC;;AAuErC,CA7EA,EA6EiC,CAAjC,EA7EA,GA6ES,GAAa;;AACtB,CA9EA,EA8EiC,IAAjC,EAAS,GAAa;;AACtB,CA/EA,EA+EiC,EAAjC,EA/EA,EA+ES,GAAa;;AAGtB,CAlFA,EAkFE,MAAA;CACA,KAAA,MAAA;AAAe,CAAf,CAAA,CAAe,MAAa,GAA5B;CAAA,CAEA,CAA6B,CAF7B,KAES,GAAgC,IAAzC;CACU,EAAmB,MAA7B,GAAyC,IAAzC;CAJA"
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var _ref,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
Annotator.Plugin.AnnotateItPermissions = (function(_super) {
|
||||
__extends(AnnotateItPermissions, _super);
|
||||
|
||||
function AnnotateItPermissions() {
|
||||
this._setAuthFromToken = __bind(this._setAuthFromToken, this);
|
||||
this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
|
||||
this.updatePermissionsField = __bind(this.updatePermissionsField, this);
|
||||
this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
|
||||
_ref = AnnotateItPermissions.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
AnnotateItPermissions.prototype.options = {
|
||||
showViewPermissionsCheckbox: true,
|
||||
showEditPermissionsCheckbox: true,
|
||||
groups: {
|
||||
world: 'group:__world__',
|
||||
authenticated: 'group:__authenticated__',
|
||||
consumer: 'group:__consumer__'
|
||||
},
|
||||
userId: function(user) {
|
||||
return user.userId;
|
||||
},
|
||||
userString: function(user) {
|
||||
return user.userId;
|
||||
},
|
||||
userAuthorize: function(action, annotation, user) {
|
||||
var action_field, permissions, _ref1, _ref2, _ref3, _ref4;
|
||||
permissions = annotation.permissions || {};
|
||||
action_field = permissions[action] || [];
|
||||
if (_ref1 = this.groups.world, __indexOf.call(action_field, _ref1) >= 0) {
|
||||
return true;
|
||||
} else if ((user != null) && (user.userId != null) && (user.consumerKey != null)) {
|
||||
if (user.userId === annotation.user && user.consumerKey === annotation.consumer) {
|
||||
return true;
|
||||
} else if (_ref2 = this.groups.authenticated, __indexOf.call(action_field, _ref2) >= 0) {
|
||||
return true;
|
||||
} else if (user.consumerKey === annotation.consumer && (_ref3 = this.groups.consumer, __indexOf.call(action_field, _ref3) >= 0)) {
|
||||
return true;
|
||||
} else if (user.consumerKey === annotation.consumer && (_ref4 = user.userId, __indexOf.call(action_field, _ref4) >= 0)) {
|
||||
return true;
|
||||
} else if (user.consumerKey === annotation.consumer && user.admin) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
permissions: {
|
||||
'read': ['group:__world__'],
|
||||
'update': [],
|
||||
'delete': [],
|
||||
'admin': []
|
||||
}
|
||||
};
|
||||
|
||||
AnnotateItPermissions.prototype.addFieldsToAnnotation = function(annotation) {
|
||||
if (annotation) {
|
||||
annotation.permissions = this.options.permissions;
|
||||
if (this.user) {
|
||||
annotation.user = this.user.userId;
|
||||
return annotation.consumer = this.user.consumerKey;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AnnotateItPermissions.prototype.updatePermissionsField = function(action, field, annotation) {
|
||||
var input;
|
||||
field = $(field).show();
|
||||
input = field.find('input').removeAttr('disabled');
|
||||
if (!this.authorize('admin', annotation)) {
|
||||
field.hide();
|
||||
}
|
||||
if (this.user && this.authorize(action, annotation || {}, {
|
||||
userId: '__nonexistentuser__',
|
||||
consumerKey: this.user.consumerKey
|
||||
})) {
|
||||
return input.attr('checked', 'checked');
|
||||
} else {
|
||||
return input.removeAttr('checked');
|
||||
}
|
||||
};
|
||||
|
||||
AnnotateItPermissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
|
||||
var dataKey;
|
||||
if (!annotation.permissions) {
|
||||
annotation.permissions = this.options.permissions;
|
||||
}
|
||||
dataKey = type + '-permissions';
|
||||
if ($(field).find('input').is(':checked')) {
|
||||
return annotation.permissions[type] = [type === 'read' ? this.options.groups.world : this.options.groups.consumer];
|
||||
} else {
|
||||
return annotation.permissions[type] = [];
|
||||
}
|
||||
};
|
||||
|
||||
AnnotateItPermissions.prototype._setAuthFromToken = function(token) {
|
||||
return this.setUser(token);
|
||||
};
|
||||
|
||||
return AnnotateItPermissions;
|
||||
|
||||
})(Annotator.Plugin.Permissions);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=annotateitpermissions.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "annotateitpermissions.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/annotateitpermissions.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAYA,IAAA;GAAA;;;wJAAA;;AAAM,CAAN,KAAsB,GAAP;CAGb;;;;;;;;;CAAA;;CAAA,EAGE,IAHF;CAGE,CAA6B,EAA7B,uBAAA;CAAA,CAG6B,EAA7B,uBAAA;CAHA,CAOE,EADF,EAAA;CACE,CAAO,GAAP,CAAA,WAAA;CAAA,CACe,IAAf,OA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IAAvB,EAAU,KAAV;QAJJ;MADqB;CAtEvB,EAsEuB;;CAtEvB,CAoFiC,CAAT,EAAA,CAAA,GAAC,CAAD,YAAxB;CACE,IAAA,GAAA;CAAA,EAAQ,CAAR,CAAA;CAAA,EACQ,CAAR,CAAA,EAAQ,GAAA;AAGY,CAApB,CAA4C,EAA5C,GAAoB,EAAA,CAAA;CAApB,GAAA,CAAK,CAAL;MAJA;CAOA,CAAoC,EAApC,EAAa,GAAA,CAAuB;CAAkB,CAAS,IAAR,eAAD;CAAA,CAA6C,EAAC,EAAd,KAAA;CAAtF,KAAa;CACL,CAAgB,EAAtB,CAAK,IAAL,IAAA;MADF;CAGQ,IAAD,IAAL,CAAA,GAAA;MAXoB;CApFxB,EAoFwB;;CApFxB,CA0GoC,CAAP,CAAA,CAAA,IAAC,CAAD,iBAA7B;CACE,MAAA,CAAA;AAAqD,CAArD,GAAA,MAA+D,CAA/D;CAAA,EAAyB,CAAC,EAA1B,CAAiC,GAAvB,CAAV;MAAA;CAAA,EAEU,CAAV,GAAA,OAFA;CAIA,CAAG,EAAH,CAAG,EAAA,GAAA;CACU,EAAoB,CAAR,CAAoB,CAAX,CAA+B,CAAhC,EAArB,CAAa,EAAvB;MADF;CAGa,EAAoB,CAAR,MAAb,CAAa,EAAvB;MARyB;CA1G7B,EA0G6B;;CA1G7B,EA0HmB,EAAA,IAAC,QAApB;CACO,GAAD,CAAJ,EAAA,IAAA;CA3HF,EA0HmB;;CA1HnB;;CAHmD,KAAgB,GAAP"
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
createDateFromISO8601 = function(string) {
|
||||
var d, date, offset, regexp, time, _ref;
|
||||
regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" + "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\\.([0-9]+))?)?" + "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
|
||||
d = string.match(new RegExp(regexp));
|
||||
offset = 0;
|
||||
date = new Date(d[1], 0, 1);
|
||||
if (d[3]) {
|
||||
date.setMonth(d[3] - 1);
|
||||
}
|
||||
if (d[5]) {
|
||||
date.setDate(d[5]);
|
||||
}
|
||||
if (d[7]) {
|
||||
date.setHours(d[7]);
|
||||
}
|
||||
if (d[8]) {
|
||||
date.setMinutes(d[8]);
|
||||
}
|
||||
if (d[10]) {
|
||||
date.setSeconds(d[10]);
|
||||
}
|
||||
if (d[12]) {
|
||||
date.setMilliseconds(Number("0." + d[12]) * 1000);
|
||||
}
|
||||
if (d[14]) {
|
||||
offset = (Number(d[16]) * 60) + Number(d[17]);
|
||||
offset *= (_ref = d[15] === '-') != null ? _ref : {
|
||||
1: -1
|
||||
};
|
||||
}
|
||||
offset -= date.getTimezoneOffset();
|
||||
time = Number(date) + (offset * 60 * 1000);
|
||||
date.setTime(Number(time));
|
||||
return date;
|
||||
};
|
||||
|
||||
base64Decode = function(data) {
|
||||
var ac, b64, bits, dec, h1, h2, h3, h4, i, o1, o2, o3, tmp_arr;
|
||||
if (typeof atob !== "undefined" && atob !== null) {
|
||||
return atob(data);
|
||||
} else {
|
||||
b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
i = 0;
|
||||
ac = 0;
|
||||
dec = "";
|
||||
tmp_arr = [];
|
||||
if (!data) {
|
||||
return data;
|
||||
}
|
||||
data += '';
|
||||
while (i < data.length) {
|
||||
h1 = b64.indexOf(data.charAt(i++));
|
||||
h2 = b64.indexOf(data.charAt(i++));
|
||||
h3 = b64.indexOf(data.charAt(i++));
|
||||
h4 = b64.indexOf(data.charAt(i++));
|
||||
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
|
||||
o1 = bits >> 16 & 0xff;
|
||||
o2 = bits >> 8 & 0xff;
|
||||
o3 = bits & 0xff;
|
||||
if (h3 === 64) {
|
||||
tmp_arr[ac++] = String.fromCharCode(o1);
|
||||
} else if (h4 === 64) {
|
||||
tmp_arr[ac++] = String.fromCharCode(o1, o2);
|
||||
} else {
|
||||
tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
|
||||
}
|
||||
}
|
||||
return tmp_arr.join('');
|
||||
}
|
||||
};
|
||||
|
||||
base64UrlDecode = function(data) {
|
||||
var i, m, _i, _ref;
|
||||
m = data.length % 4;
|
||||
if (m !== 0) {
|
||||
for (i = _i = 0, _ref = 4 - m; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
|
||||
data += '=';
|
||||
}
|
||||
}
|
||||
data = data.replace(/-/g, '+');
|
||||
data = data.replace(/_/g, '/');
|
||||
return base64Decode(data);
|
||||
};
|
||||
|
||||
parseToken = function(token) {
|
||||
var head, payload, sig, _ref;
|
||||
_ref = token.split('.'), head = _ref[0], payload = _ref[1], sig = _ref[2];
|
||||
return JSON.parse(base64UrlDecode(payload));
|
||||
};
|
||||
|
||||
Annotator.Plugin.Auth = (function(_super) {
|
||||
__extends(Auth, _super);
|
||||
|
||||
Auth.prototype.options = {
|
||||
token: null,
|
||||
tokenUrl: '/auth/token',
|
||||
autoFetch: true
|
||||
};
|
||||
|
||||
function Auth(element, options) {
|
||||
Auth.__super__.constructor.apply(this, arguments);
|
||||
this.waitingForToken = [];
|
||||
if (this.options.token) {
|
||||
this.setToken(this.options.token);
|
||||
} else {
|
||||
this.requestToken();
|
||||
}
|
||||
}
|
||||
|
||||
Auth.prototype.requestToken = function() {
|
||||
var _this = this;
|
||||
this.requestInProgress = true;
|
||||
return $.ajax({
|
||||
url: this.options.tokenUrl,
|
||||
dataType: 'text',
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
}
|
||||
}).done(function(data, status, xhr) {
|
||||
return _this.setToken(data);
|
||||
}).fail(function(xhr, status, err) {
|
||||
var msg;
|
||||
msg = Annotator._t("Couldn't get auth token:");
|
||||
console.error("" + msg + " " + err, xhr);
|
||||
return Annotator.showNotification("" + msg + " " + xhr.responseText, Annotator.Notification.ERROR);
|
||||
}).always(function() {
|
||||
return _this.requestInProgress = false;
|
||||
});
|
||||
};
|
||||
|
||||
Auth.prototype.setToken = function(token) {
|
||||
var _results,
|
||||
_this = this;
|
||||
this.token = token;
|
||||
this._unsafeToken = parseToken(token);
|
||||
if (this.haveValidToken()) {
|
||||
if (this.options.autoFetch) {
|
||||
this.refreshTimeout = setTimeout((function() {
|
||||
return _this.requestToken();
|
||||
}), (this.timeToExpiry() - 2) * 1000);
|
||||
}
|
||||
this.updateHeaders();
|
||||
_results = [];
|
||||
while (this.waitingForToken.length > 0) {
|
||||
_results.push(this.waitingForToken.pop()(this._unsafeToken));
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
console.warn(Annotator._t("Didn't get a valid token."));
|
||||
if (this.options.autoFetch) {
|
||||
console.warn(Annotator._t("Getting a new token in 10s."));
|
||||
return setTimeout((function() {
|
||||
return _this.requestToken();
|
||||
}), 10 * 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Auth.prototype.haveValidToken = function() {
|
||||
var allFields;
|
||||
allFields = this._unsafeToken && this._unsafeToken.issuedAt && this._unsafeToken.ttl && this._unsafeToken.consumerKey;
|
||||
if (allFields && this.timeToExpiry() > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Auth.prototype.timeToExpiry = function() {
|
||||
var expiry, issue, now, timeToExpiry;
|
||||
now = new Date().getTime() / 1000;
|
||||
issue = createDateFromISO8601(this._unsafeToken.issuedAt).getTime() / 1000;
|
||||
expiry = issue + this._unsafeToken.ttl;
|
||||
timeToExpiry = expiry - now;
|
||||
if (timeToExpiry > 0) {
|
||||
return timeToExpiry;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Auth.prototype.updateHeaders = function() {
|
||||
var current;
|
||||
current = this.element.data('annotator:headers');
|
||||
return this.element.data('annotator:headers', $.extend(current, {
|
||||
'x-annotator-auth-token': this.token
|
||||
}));
|
||||
};
|
||||
|
||||
Auth.prototype.withToken = function(callback) {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
if (this.haveValidToken()) {
|
||||
return callback(this._unsafeToken);
|
||||
} else {
|
||||
this.waitingForToken.push(callback);
|
||||
if (!this.requestInProgress) {
|
||||
return this.requestToken();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Auth;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=auth.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "auth.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/auth.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAKA,IAAA,4DAAA;GAAA;kSAAA;;AAAA,CAAA,EAAwB,GAAA,GAAC,YAAzB;CACE,KAAA,6BAAA;CAAA,CAAA,CAAS,GAAT,8BAAS,MAAT,WAAS;CAAT,CAIA,CAAI,CAAiB,CAAjB,CAAM;CAJV,CAMA,CAAS,GAAT;CANA,CAOA,CAAW,CAAX;CAEA,CAAA,EAA2B;CAA3B,EAAqB,CAArB,IAAA;IATA;CAUA,CAAA,EAAsB;CAAtB,GAAA,GAAA;IAVA;CAWA,CAAA,EAAuB;CAAvB,GAAA,IAAA;IAXA;CAYA,CAAA,EAAyB;CAAzB,GAAA,MAAA;IAZA;CAaA,CAAA,EAA0B;CAA1B,CAAkB,EAAlB,MAAA;IAbA;CAcA,CAAA,EAAqD;CAArD,CAAqC,CAAF,CAAnC,EAAqB,SAArB;IAdA;CAgBA,CAAA,EAAG;CACD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CACnD,kBAAA;CADF,KAAmC;CAxIrC,EAsIe;;CAtIf,EAuJW,KAAA,CAAX;CACE,GAAA,YAAA;CACE,WAAA;MADF;CAGA,GAAA,UAAG;CACQ,GAAC,IAAV,IAAA,CAAA;MADF;CAGE,GAAI,EAAJ,EAAA,OAAoB;AACb,CAAP,GAAG,EAAH,WAAA;CACO,GAAD,QAAJ,GAAA;QALJ;MAJS;CAvJX,EAuJW;;CAvJX;;CAFkC,QAAS"
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var _ref,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Plugin.Document = (function(_super) {
|
||||
var $;
|
||||
|
||||
__extends(Document, _super);
|
||||
|
||||
function Document() {
|
||||
this._getFavicon = __bind(this._getFavicon, this);
|
||||
this._getLinks = __bind(this._getLinks, this);
|
||||
this._getTitle = __bind(this._getTitle, this);
|
||||
this._getMetaTags = __bind(this._getMetaTags, this);
|
||||
this._getEprints = __bind(this._getEprints, this);
|
||||
this._getPrism = __bind(this._getPrism, this);
|
||||
this._getDublinCore = __bind(this._getDublinCore, this);
|
||||
this._getTwitter = __bind(this._getTwitter, this);
|
||||
this._getFacebook = __bind(this._getFacebook, this);
|
||||
this._getHighwire = __bind(this._getHighwire, this);
|
||||
this.getDocumentMetadata = __bind(this.getDocumentMetadata, this);
|
||||
this.beforeAnnotationCreated = __bind(this.beforeAnnotationCreated, this);
|
||||
this.uris = __bind(this.uris, this);
|
||||
this.uri = __bind(this.uri, this);
|
||||
_ref = Document.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
$ = Annotator.$;
|
||||
|
||||
Document.prototype.events = {
|
||||
'beforeAnnotationCreated': 'beforeAnnotationCreated'
|
||||
};
|
||||
|
||||
Document.prototype.pluginInit = function() {
|
||||
return this.getDocumentMetadata();
|
||||
};
|
||||
|
||||
Document.prototype.uri = function() {
|
||||
var link, uri, _i, _len, _ref1;
|
||||
uri = decodeURIComponent(document.location.href);
|
||||
_ref1 = this.metadata;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
link = _ref1[_i];
|
||||
if (link.rel === "canonical") {
|
||||
uri = link.href;
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
};
|
||||
|
||||
Document.prototype.uris = function() {
|
||||
var href, link, uniqueUrls, _i, _len, _ref1;
|
||||
uniqueUrls = {};
|
||||
_ref1 = this.metadata.link;
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
link = _ref1[_i];
|
||||
if (link.href) {
|
||||
uniqueUrls[link.href] = true;
|
||||
}
|
||||
}
|
||||
return (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (href in uniqueUrls) {
|
||||
_results.push(href);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
};
|
||||
|
||||
Document.prototype.beforeAnnotationCreated = function(annotation) {
|
||||
return annotation.document = this.metadata;
|
||||
};
|
||||
|
||||
Document.prototype.getDocumentMetadata = function() {
|
||||
this.metadata = {};
|
||||
this._getHighwire();
|
||||
this._getDublinCore();
|
||||
this._getFacebook();
|
||||
this._getEprints();
|
||||
this._getPrism();
|
||||
this._getTwitter();
|
||||
this._getFavicon();
|
||||
this._getTitle();
|
||||
this._getLinks();
|
||||
return this.metadata;
|
||||
};
|
||||
|
||||
Document.prototype._getHighwire = function() {
|
||||
return this.metadata.highwire = this._getMetaTags("citation", "name", "_");
|
||||
};
|
||||
|
||||
Document.prototype._getFacebook = function() {
|
||||
return this.metadata.facebook = this._getMetaTags("og", "property", ":");
|
||||
};
|
||||
|
||||
Document.prototype._getTwitter = function() {
|
||||
return this.metadata.twitter = this._getMetaTags("twitter", "name", ":");
|
||||
};
|
||||
|
||||
Document.prototype._getDublinCore = function() {
|
||||
return this.metadata.dc = this._getMetaTags("dc", "name", ".");
|
||||
};
|
||||
|
||||
Document.prototype._getPrism = function() {
|
||||
return this.metadata.prism = this._getMetaTags("prism", "name", ".");
|
||||
};
|
||||
|
||||
Document.prototype._getEprints = function() {
|
||||
return this.metadata.eprints = this._getMetaTags("eprints", "name", ".");
|
||||
};
|
||||
|
||||
Document.prototype._getMetaTags = function(prefix, attribute, delimiter) {
|
||||
var content, match, meta, n, name, tags, _i, _len, _ref1;
|
||||
tags = {};
|
||||
_ref1 = $("meta");
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
meta = _ref1[_i];
|
||||
name = $(meta).attr(attribute);
|
||||
content = $(meta).prop("content");
|
||||
if (name) {
|
||||
match = name.match(RegExp("^" + prefix + delimiter + "(.+)$", "i"));
|
||||
if (match) {
|
||||
n = match[1];
|
||||
if (tags[n]) {
|
||||
tags[n].push(content);
|
||||
} else {
|
||||
tags[n] = [content];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
};
|
||||
|
||||
Document.prototype._getTitle = function() {
|
||||
if (this.metadata.highwire.title) {
|
||||
return this.metadata.title = this.metadata.highwire.title[0];
|
||||
} else if (this.metadata.eprints.title) {
|
||||
return this.metadata.title = this.metadata.eprints.title;
|
||||
} else if (this.metadata.prism.title) {
|
||||
return this.metadata.title = this.metadata.prism.title;
|
||||
} else if (this.metadata.facebook.title) {
|
||||
return this.metadata.title = this.metadata.facebook.title;
|
||||
} else if (this.metadata.twitter.title) {
|
||||
return this.metadata.title = this.metadata.twitter.title;
|
||||
} else if (this.metadata.dc.title) {
|
||||
return this.metadata.title = this.metadata.dc.title;
|
||||
} else {
|
||||
return this.metadata.title = $("head title").text();
|
||||
}
|
||||
};
|
||||
|
||||
Document.prototype._getLinks = function() {
|
||||
var doi, href, id, l, link, name, rel, type, url, values, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results;
|
||||
this.metadata.link = [
|
||||
{
|
||||
href: document.location.href
|
||||
}
|
||||
];
|
||||
_ref1 = $("link");
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
link = _ref1[_i];
|
||||
l = $(link);
|
||||
href = this._absoluteUrl(l.prop('href'));
|
||||
rel = l.prop('rel');
|
||||
type = l.prop('type');
|
||||
if ((rel === "alternate" || rel === "canonical" || rel === "bookmark") && (type !== "application/rss+xml" && type !== "application/atom+xml")) {
|
||||
this.metadata.link.push({
|
||||
href: href,
|
||||
rel: rel,
|
||||
type: type
|
||||
});
|
||||
}
|
||||
}
|
||||
_ref2 = this.metadata.highwire;
|
||||
for (name in _ref2) {
|
||||
values = _ref2[name];
|
||||
if (name === "pdf_url") {
|
||||
for (_j = 0, _len1 = values.length; _j < _len1; _j++) {
|
||||
url = values[_j];
|
||||
this.metadata.link.push({
|
||||
href: this._absoluteUrl(url),
|
||||
type: "application/pdf"
|
||||
});
|
||||
}
|
||||
}
|
||||
if (name === "doi") {
|
||||
for (_k = 0, _len2 = values.length; _k < _len2; _k++) {
|
||||
doi = values[_k];
|
||||
if (doi.slice(0, 4) !== "doi:") {
|
||||
doi = "doi:" + doi;
|
||||
}
|
||||
this.metadata.link.push({
|
||||
href: doi
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
_ref3 = this.metadata.dc;
|
||||
_results = [];
|
||||
for (name in _ref3) {
|
||||
values = _ref3[name];
|
||||
if (name === "identifier") {
|
||||
_results.push((function() {
|
||||
var _l, _len3, _results1;
|
||||
_results1 = [];
|
||||
for (_l = 0, _len3 = values.length; _l < _len3; _l++) {
|
||||
id = values[_l];
|
||||
if (id.slice(0, 4) === "doi:") {
|
||||
_results1.push(this.metadata.link.push({
|
||||
href: id
|
||||
}));
|
||||
} else {
|
||||
_results1.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results1;
|
||||
}).call(this));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Document.prototype._getFavicon = function() {
|
||||
var link, _i, _len, _ref1, _ref2, _results;
|
||||
_ref1 = $("link");
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
link = _ref1[_i];
|
||||
if ((_ref2 = $(link).prop("rel")) === "shortcut icon" || _ref2 === "icon") {
|
||||
_results.push(this.metadata["favicon"] = this._absoluteUrl(link.href));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Document.prototype._absoluteUrl = function(url) {
|
||||
var img;
|
||||
img = $("<img src='" + url + "'>");
|
||||
url = img.prop('src');
|
||||
img.prop('src', null);
|
||||
return url;
|
||||
};
|
||||
|
||||
return Document;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=document.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "document.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/document.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAAA,IAAA;GAAA;;kSAAA;;AAAM,CAAN,KAAsB,GAAP;CAEb,KAAA;;CAAA;;;;;;;;;;;;;;;;;;;CAAA;;CAAA,CAAA,CAAI,MAAS;;CAAb,EAGE,GADF;CACE,CAA2B,EAA3B,qBAAA;CAHF,GAAA;;CAAA,EAKY,MAAA,CAAZ;CACO,GAAD,OAAJ,QAAA;CANF,EAKY;;CALZ,EAUA,MAAK;CACH,OAAA,kBAAA;CAAA,EAAA,CAAA,IAAiC,UAA3B;CACN;CAAA,QAAA,mCAAA;wBAAA;CACE,EAAG,CAAA,CAAY,CAAf,KAAA;CACE,EAAA,CAAU,IAAV;QAFJ;CAAA,IADA;CAIA,EAAA,QAAO;CAfT,EAUK;;CAVL,EAmBM,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-1,282 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Plugin.Filter = (function(_super) {
|
||||
__extends(Filter, _super);
|
||||
|
||||
Filter.prototype.events = {
|
||||
".annotator-filter-property input focus": "_onFilterFocus",
|
||||
".annotator-filter-property input blur": "_onFilterBlur",
|
||||
".annotator-filter-property input keyup": "_onFilterKeyup",
|
||||
".annotator-filter-previous click": "_onPreviousClick",
|
||||
".annotator-filter-next click": "_onNextClick",
|
||||
".annotator-filter-clear click": "_onClearClick"
|
||||
};
|
||||
|
||||
Filter.prototype.classes = {
|
||||
active: 'annotator-filter-active',
|
||||
hl: {
|
||||
hide: 'annotator-hl-filtered',
|
||||
active: 'annotator-hl-active'
|
||||
}
|
||||
};
|
||||
|
||||
Filter.prototype.html = {
|
||||
element: "<div class=\"annotator-filter\">\n <strong>" + Annotator._t('Navigate:') + "</strong>\n<span class=\"annotator-filter-navigation\">\n <button class=\"annotator-filter-previous\">" + Annotator._t('Previous') + "</button>\n<button class=\"annotator-filter-next\">" + Annotator._t('Next') + "</button>\n</span>\n<strong>" + Annotator._t('Filter by:') + "</strong>\n</div>",
|
||||
filter: "<span class=\"annotator-filter-property\">\n <label></label>\n <input/>\n <button class=\"annotator-filter-clear\">" + Annotator._t('Clear') + "</button>\n</span>"
|
||||
};
|
||||
|
||||
Filter.prototype.options = {
|
||||
appendTo: 'body',
|
||||
filters: [],
|
||||
addAnnotationFilter: true,
|
||||
isFiltered: function(input, property) {
|
||||
var keyword, _i, _len, _ref;
|
||||
if (!(input && property)) {
|
||||
return false;
|
||||
}
|
||||
_ref = input.split(/\s*/);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
keyword = _ref[_i];
|
||||
if (property.indexOf(keyword) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
function Filter(element, options) {
|
||||
this._onPreviousClick = __bind(this._onPreviousClick, this);
|
||||
this._onNextClick = __bind(this._onNextClick, this);
|
||||
this._onFilterKeyup = __bind(this._onFilterKeyup, this);
|
||||
this._onFilterBlur = __bind(this._onFilterBlur, this);
|
||||
this._onFilterFocus = __bind(this._onFilterFocus, this);
|
||||
this.updateHighlights = __bind(this.updateHighlights, this);
|
||||
var _base;
|
||||
element = $(this.html.element).appendTo((options != null ? options.appendTo : void 0) || this.options.appendTo);
|
||||
Filter.__super__.constructor.call(this, element, options);
|
||||
(_base = this.options).filters || (_base.filters = []);
|
||||
this.filter = $(this.html.filter);
|
||||
this.filters = [];
|
||||
this.current = 0;
|
||||
}
|
||||
|
||||
Filter.prototype.pluginInit = function() {
|
||||
var filter, _i, _len, _ref;
|
||||
_ref = this.options.filters;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
filter = _ref[_i];
|
||||
this.addFilter(filter);
|
||||
}
|
||||
this.updateHighlights();
|
||||
this._setupListeners()._insertSpacer();
|
||||
if (this.options.addAnnotationFilter === true) {
|
||||
return this.addFilter({
|
||||
label: Annotator._t('Annotation'),
|
||||
property: 'text'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Filter.prototype.destroy = function() {
|
||||
var currentMargin, html;
|
||||
Filter.__super__.destroy.apply(this, arguments);
|
||||
html = $('html');
|
||||
currentMargin = parseInt(html.css('padding-top'), 10) || 0;
|
||||
html.css('padding-top', currentMargin - this.element.outerHeight());
|
||||
return this.element.remove();
|
||||
};
|
||||
|
||||
Filter.prototype._insertSpacer = function() {
|
||||
var currentMargin, html;
|
||||
html = $('html');
|
||||
currentMargin = parseInt(html.css('padding-top'), 10) || 0;
|
||||
html.css('padding-top', currentMargin + this.element.outerHeight());
|
||||
return this;
|
||||
};
|
||||
|
||||
Filter.prototype._setupListeners = function() {
|
||||
var event, events, _i, _len;
|
||||
events = ['annotationsLoaded', 'annotationCreated', 'annotationUpdated', 'annotationDeleted'];
|
||||
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
||||
event = events[_i];
|
||||
this.annotator.subscribe(event, this.updateHighlights);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Filter.prototype.addFilter = function(options) {
|
||||
var f, filter;
|
||||
filter = $.extend({
|
||||
label: '',
|
||||
property: '',
|
||||
isFiltered: this.options.isFiltered
|
||||
}, options);
|
||||
if (!((function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = this.filters;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
f = _ref[_i];
|
||||
if (f.property === filter.property) {
|
||||
_results.push(f);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
}).call(this)).length) {
|
||||
filter.id = 'annotator-filter-' + filter.property;
|
||||
filter.annotations = [];
|
||||
filter.element = this.filter.clone().appendTo(this.element);
|
||||
filter.element.find('label').html(filter.label).attr('for', filter.id);
|
||||
filter.element.find('input').attr({
|
||||
id: filter.id,
|
||||
placeholder: Annotator._t('Filter by ') + filter.label + '\u2026'
|
||||
});
|
||||
filter.element.find('button').hide();
|
||||
filter.element.data('filter', filter);
|
||||
this.filters.push(filter);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Filter.prototype.updateFilter = function(filter) {
|
||||
var annotation, annotations, input, property, _i, _len, _ref;
|
||||
filter.annotations = [];
|
||||
this.updateHighlights();
|
||||
this.resetHighlights();
|
||||
input = $.trim(filter.element.find('input').val());
|
||||
if (input) {
|
||||
annotations = this.highlights.map(function() {
|
||||
return $(this).data('annotation');
|
||||
});
|
||||
_ref = $.makeArray(annotations);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
annotation = _ref[_i];
|
||||
property = annotation[filter.property];
|
||||
if (filter.isFiltered(input, property)) {
|
||||
filter.annotations.push(annotation);
|
||||
}
|
||||
}
|
||||
return this.filterHighlights();
|
||||
}
|
||||
};
|
||||
|
||||
Filter.prototype.updateHighlights = function() {
|
||||
this.highlights = this.annotator.element.find('.annotator-hl:visible');
|
||||
return this.filtered = this.highlights.not(this.classes.hl.hide);
|
||||
};
|
||||
|
||||
Filter.prototype.filterHighlights = function() {
|
||||
var activeFilters, annotation, annotations, filtered, highlights, index, uniques, _i, _len, _ref;
|
||||
activeFilters = $.grep(this.filters, function(filter) {
|
||||
return !!filter.annotations.length;
|
||||
});
|
||||
filtered = ((_ref = activeFilters[0]) != null ? _ref.annotations : void 0) || [];
|
||||
if (activeFilters.length > 1) {
|
||||
annotations = [];
|
||||
$.each(activeFilters, function() {
|
||||
return $.merge(annotations, this.annotations);
|
||||
});
|
||||
uniques = [];
|
||||
filtered = [];
|
||||
$.each(annotations, function() {
|
||||
if ($.inArray(this, uniques) === -1) {
|
||||
return uniques.push(this);
|
||||
} else {
|
||||
return filtered.push(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
highlights = this.highlights;
|
||||
for (index = _i = 0, _len = filtered.length; _i < _len; index = ++_i) {
|
||||
annotation = filtered[index];
|
||||
highlights = highlights.not(annotation.highlights);
|
||||
}
|
||||
highlights.addClass(this.classes.hl.hide);
|
||||
this.filtered = this.highlights.not(this.classes.hl.hide);
|
||||
return this;
|
||||
};
|
||||
|
||||
Filter.prototype.resetHighlights = function() {
|
||||
this.highlights.removeClass(this.classes.hl.hide);
|
||||
this.filtered = this.highlights;
|
||||
return this;
|
||||
};
|
||||
|
||||
Filter.prototype._onFilterFocus = function(event) {
|
||||
var input;
|
||||
input = $(event.target);
|
||||
input.parent().addClass(this.classes.active);
|
||||
return input.next('button').show();
|
||||
};
|
||||
|
||||
Filter.prototype._onFilterBlur = function(event) {
|
||||
var input;
|
||||
if (!event.target.value) {
|
||||
input = $(event.target);
|
||||
input.parent().removeClass(this.classes.active);
|
||||
return input.next('button').hide();
|
||||
}
|
||||
};
|
||||
|
||||
Filter.prototype._onFilterKeyup = function(event) {
|
||||
var filter;
|
||||
filter = $(event.target).parent().data('filter');
|
||||
if (filter) {
|
||||
return this.updateFilter(filter);
|
||||
}
|
||||
};
|
||||
|
||||
Filter.prototype._findNextHighlight = function(previous) {
|
||||
var active, annotation, current, index, next, offset, operator, resetOffset;
|
||||
if (!this.highlights.length) {
|
||||
return this;
|
||||
}
|
||||
offset = previous ? 0 : -1;
|
||||
resetOffset = previous ? -1 : 0;
|
||||
operator = previous ? 'lt' : 'gt';
|
||||
active = this.highlights.not('.' + this.classes.hl.hide);
|
||||
current = active.filter('.' + this.classes.hl.active);
|
||||
if (!current.length) {
|
||||
current = active.eq(offset);
|
||||
}
|
||||
annotation = current.data('annotation');
|
||||
index = active.index(current[0]);
|
||||
next = active.filter(":" + operator + "(" + index + ")").not(annotation.highlights).eq(resetOffset);
|
||||
if (!next.length) {
|
||||
next = active.eq(resetOffset);
|
||||
}
|
||||
return this._scrollToHighlight(next.data('annotation').highlights);
|
||||
};
|
||||
|
||||
Filter.prototype._onNextClick = function(event) {
|
||||
return this._findNextHighlight();
|
||||
};
|
||||
|
||||
Filter.prototype._onPreviousClick = function(event) {
|
||||
return this._findNextHighlight(true);
|
||||
};
|
||||
|
||||
Filter.prototype._scrollToHighlight = function(highlight) {
|
||||
highlight = $(highlight);
|
||||
this.highlights.removeClass(this.classes.hl.active);
|
||||
highlight.addClass(this.classes.hl.active);
|
||||
return $('html, body').animate({
|
||||
scrollTop: highlight.offset().top - (this.element.height() + 20)
|
||||
}, 150);
|
||||
};
|
||||
|
||||
Filter.prototype._onClearClick = function(event) {
|
||||
return $(event.target).prev('input').val('').keyup().blur();
|
||||
};
|
||||
|
||||
return Filter;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=filter.map
|
||||
*/
|
File diff suppressed because one or more lines are too long
|
@ -1,67 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var __hasProp = {}.hasOwnProperty,
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
Annotator.prototype.setupPlugins = function(config, options) {
|
||||
var name, opts, pluginConfig, plugins, uri, win, _i, _len, _results;
|
||||
if (config == null) {
|
||||
config = {};
|
||||
}
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
win = Annotator.Util.getGlobal();
|
||||
plugins = ['Unsupported', 'Auth', 'Tags', 'Filter', 'Store', 'AnnotateItPermissions'];
|
||||
if (win.Showdown) {
|
||||
plugins.push('Markdown');
|
||||
}
|
||||
uri = win.location.href.split(/#|\?/).shift() || '';
|
||||
pluginConfig = {
|
||||
Tags: {},
|
||||
Filter: {
|
||||
filters: [
|
||||
{
|
||||
label: Annotator._t('User'),
|
||||
property: 'user'
|
||||
}, {
|
||||
label: Annotator._t('Tags'),
|
||||
property: 'tags'
|
||||
}
|
||||
]
|
||||
},
|
||||
Auth: {
|
||||
tokenUrl: config.tokenUrl || 'http://annotateit.org/api/token'
|
||||
},
|
||||
Store: {
|
||||
prefix: config.storeUrl || 'http://annotateit.org/api',
|
||||
annotationData: {
|
||||
uri: uri
|
||||
},
|
||||
loadFromSearch: {
|
||||
uri: uri
|
||||
}
|
||||
}
|
||||
};
|
||||
for (name in options) {
|
||||
if (!__hasProp.call(options, name)) continue;
|
||||
opts = options[name];
|
||||
if (__indexOf.call(plugins, name) < 0) {
|
||||
plugins.push(name);
|
||||
}
|
||||
}
|
||||
$.extend(true, pluginConfig, options);
|
||||
_results = [];
|
||||
for (_i = 0, _len = plugins.length; _i < _len; _i++) {
|
||||
name = plugins[_i];
|
||||
if (!(name in pluginConfig) || pluginConfig[name]) {
|
||||
_results.push(this.addPlugin(name, pluginConfig[name]));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=kitchensink.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "kitchensink.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/kitchensink.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AA2BA,IAAA;wJAAA;;AAAA,CAAA,CAAsC,CAAZ,GAAA,CAAA,EAAjB,GAAT;CACE,KAAA,yDAAA;;GADgC,CAAP;IACzB;;GAD4C,CAAR;IACpC;CAAA,CAAA,CAAA,CAAoB,KAAL;CAAf,CAGA,CAAU,GAAA,CAAV,CAAU,KAAA,UAAA;CAGV,CAAA,CAAM,CAAH,IAAH;CACE,GAAA,GAAO,GAAP;IAPF;CAAA,CAUA,CAAA,CAAuB,CAAjB,CAAA,EAAY;CAVlB,CAYA,CACE,SADF;CACE,CAAM,EAAN;CAAA,CAEE,EADF,EAAA;CACE,CAAS,IAAT,CAAA;SACE;CAAA,CAAQ,GAAP,CAAO,GAAS,CAAhB;CAAD,CAAwC,IAAxC,EAA8B,EAAA;EAC9B,QAFO;CAEP,CAAQ,GAAP,CAAO,GAAS,CAAhB;CAAD,CAAwC,IAAxC,EAA8B,EAAA;UAFvB;QAAT;MAFF;CAAA,CAOE,EADF;CACE,CAAU,EAAmB,EAA7B,EAAA,yBAAA;MAPF;CAAA,CASE,EADF,CAAA;CACE,CAAQ,EAAmB,EAA3B,EAAQ,mBAAR;CAAA,CAEE,IADF,QAAA;CACE,CAAK,CAAL,KAAA;QAFF;CAAA,CAIE,IADF,QAAA;CACE,CAAK,CAAL,KAAA;QAJF;MATF;CAbF,GAAA;AA4BA,CAAA,MAAA,QAAA;;0BAAA;CACE,CAAG,EAAH,CAAA,EAAG,QAAY;CACb,GAAA,EAAA,CAAO;MAFX;CAAA,EA5BA;CAAA,CAgCA,EAAA,EAAA,CAAA,KAAA;AAEA,CAAA;QAAA,sCAAA;wBAAA;AACK,CAAH,GAAA,QAAG;CACD,CAAqB,EAAjB,KAAJ,GAAkC;MADpC;CAAA;MADF;CAAA;mBAnCwB;CAAA"
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Plugin.Markdown = (function(_super) {
|
||||
__extends(Markdown, _super);
|
||||
|
||||
Markdown.prototype.events = {
|
||||
'annotationViewerTextField': 'updateTextField'
|
||||
};
|
||||
|
||||
function Markdown(element, options) {
|
||||
this.updateTextField = __bind(this.updateTextField, this);
|
||||
if ((typeof Showdown !== "undefined" && Showdown !== null ? Showdown.converter : void 0) != null) {
|
||||
Markdown.__super__.constructor.apply(this, arguments);
|
||||
this.converter = new Showdown.converter();
|
||||
} else {
|
||||
console.error(Annotator._t("To use the Markdown plugin, you must include Showdown into the page first."));
|
||||
}
|
||||
}
|
||||
|
||||
Markdown.prototype.updateTextField = function(field, annotation) {
|
||||
var text;
|
||||
text = Annotator.Util.escape(annotation.text || '');
|
||||
return $(field).html(this.convert(text));
|
||||
};
|
||||
|
||||
Markdown.prototype.convert = function(text) {
|
||||
return this.converter.makeHtml(text);
|
||||
};
|
||||
|
||||
return Markdown;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=markdown.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "markdown.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/markdown.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAEA,IAAA;;kSAAA;;AAAM,CAAN,KAAsB,GAAP;CAEb;;CAAA,EACE,GADF;CACE,CAA6B,EAA7B,aAAA,UAAA;CADF,GAAA;;CAaa,CAAA,CAAA,IAAA,WAAC;CACZ,wDAAA;CAAA,GAAA,wFAAA;CACE,KAAA,GAAA,kCAAA;CAAA,EACiB,CAAhB,EAAD,EAAyB,CAAzB;MAFF;CAIE,CAAc,GAAd,CAAA,CAAO,EAAgB,mEAAT;MALL;CAbb,EAaa;;CAbb,CAiCyB,CAAR,EAAA,IAAC,CAAD,KAAjB;CAEE,GAAA,IAAA;CAAA,CAAO,CAAA,CAAP,EAAO,GAAS,CAAuB;CACvC,GAAA,CAAA,EAAc,IAAd;CApCF,EAiCiB;;CAjCjB,EAgDS,CAAA,GAAT,EAAU;CACP,GAAA,IAAD,CAAU,EAAV;CAjDF,EAgDS;;CAhDT;;CAFsC,QAAS"
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Plugin.Permissions = (function(_super) {
|
||||
__extends(Permissions, _super);
|
||||
|
||||
Permissions.prototype.events = {
|
||||
'beforeAnnotationCreated': 'addFieldsToAnnotation'
|
||||
};
|
||||
|
||||
Permissions.prototype.options = {
|
||||
showViewPermissionsCheckbox: true,
|
||||
showEditPermissionsCheckbox: true,
|
||||
userId: function(user) {
|
||||
return user;
|
||||
},
|
||||
userString: function(user) {
|
||||
return user;
|
||||
},
|
||||
userAuthorize: function(action, annotation, user) {
|
||||
var token, tokens, _i, _len;
|
||||
if (annotation.permissions) {
|
||||
tokens = annotation.permissions[action] || [];
|
||||
if (tokens.length === 0) {
|
||||
return true;
|
||||
}
|
||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||
token = tokens[_i];
|
||||
if (this.userId(user) === token) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else if (annotation.user) {
|
||||
if (user) {
|
||||
return this.userId(user) === this.userId(annotation.user);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
user: '',
|
||||
permissions: {
|
||||
'read': [],
|
||||
'update': [],
|
||||
'delete': [],
|
||||
'admin': []
|
||||
}
|
||||
};
|
||||
|
||||
function Permissions(element, options) {
|
||||
this._setAuthFromToken = __bind(this._setAuthFromToken, this);
|
||||
this.updateViewer = __bind(this.updateViewer, this);
|
||||
this.updateAnnotationPermissions = __bind(this.updateAnnotationPermissions, this);
|
||||
this.updatePermissionsField = __bind(this.updatePermissionsField, this);
|
||||
this.addFieldsToAnnotation = __bind(this.addFieldsToAnnotation, this);
|
||||
Permissions.__super__.constructor.apply(this, arguments);
|
||||
if (this.options.user) {
|
||||
this.setUser(this.options.user);
|
||||
delete this.options.user;
|
||||
}
|
||||
}
|
||||
|
||||
Permissions.prototype.pluginInit = function() {
|
||||
var createCallback, self,
|
||||
_this = this;
|
||||
if (!Annotator.supported()) {
|
||||
return;
|
||||
}
|
||||
self = this;
|
||||
createCallback = function(method, type) {
|
||||
return function(field, annotation) {
|
||||
return self[method].call(self, type, field, annotation);
|
||||
};
|
||||
};
|
||||
if (!this.user && this.annotator.plugins.Auth) {
|
||||
this.annotator.plugins.Auth.withToken(this._setAuthFromToken);
|
||||
}
|
||||
if (this.options.showViewPermissionsCheckbox === true) {
|
||||
this.annotator.editor.addField({
|
||||
type: 'checkbox',
|
||||
label: Annotator._t('Allow anyone to <strong>view</strong> this annotation'),
|
||||
load: createCallback('updatePermissionsField', 'read'),
|
||||
submit: createCallback('updateAnnotationPermissions', 'read')
|
||||
});
|
||||
}
|
||||
if (this.options.showEditPermissionsCheckbox === true) {
|
||||
this.annotator.editor.addField({
|
||||
type: 'checkbox',
|
||||
label: Annotator._t('Allow anyone to <strong>edit</strong> this annotation'),
|
||||
load: createCallback('updatePermissionsField', 'update'),
|
||||
submit: createCallback('updateAnnotationPermissions', 'update')
|
||||
});
|
||||
}
|
||||
this.annotator.viewer.addField({
|
||||
load: this.updateViewer
|
||||
});
|
||||
if (this.annotator.plugins.Filter) {
|
||||
return this.annotator.plugins.Filter.addFilter({
|
||||
label: Annotator._t('User'),
|
||||
property: 'user',
|
||||
isFiltered: function(input, user) {
|
||||
var keyword, _i, _len, _ref;
|
||||
user = _this.options.userString(user);
|
||||
if (!(input && user)) {
|
||||
return false;
|
||||
}
|
||||
_ref = input.split(/\s*/);
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
keyword = _ref[_i];
|
||||
if (user.indexOf(keyword) === -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Permissions.prototype.setUser = function(user) {
|
||||
return this.user = user;
|
||||
};
|
||||
|
||||
Permissions.prototype.addFieldsToAnnotation = function(annotation) {
|
||||
if (annotation) {
|
||||
annotation.permissions = this.options.permissions;
|
||||
if (this.user) {
|
||||
return annotation.user = this.user;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Permissions.prototype.authorize = function(action, annotation, user) {
|
||||
if (user === void 0) {
|
||||
user = this.user;
|
||||
}
|
||||
if (this.options.userAuthorize) {
|
||||
return this.options.userAuthorize.call(this.options, action, annotation, user);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Permissions.prototype.updatePermissionsField = function(action, field, annotation) {
|
||||
var input;
|
||||
field = $(field).show();
|
||||
input = field.find('input').removeAttr('disabled');
|
||||
if (!this.authorize('admin', annotation)) {
|
||||
field.hide();
|
||||
}
|
||||
if (this.authorize(action, annotation || {}, null)) {
|
||||
return input.attr('checked', 'checked');
|
||||
} else {
|
||||
return input.removeAttr('checked');
|
||||
}
|
||||
};
|
||||
|
||||
Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
|
||||
var dataKey;
|
||||
if (!annotation.permissions) {
|
||||
annotation.permissions = this.options.permissions;
|
||||
}
|
||||
dataKey = type + '-permissions';
|
||||
if ($(field).find('input').is(':checked')) {
|
||||
return annotation.permissions[type] = [];
|
||||
} else {
|
||||
return annotation.permissions[type] = [this.user];
|
||||
}
|
||||
};
|
||||
|
||||
Permissions.prototype.updateViewer = function(field, annotation, controls) {
|
||||
var user, username;
|
||||
field = $(field);
|
||||
username = this.options.userString(annotation.user);
|
||||
if (annotation.user && username && typeof username === 'string') {
|
||||
user = Annotator.Util.escape(this.options.userString(annotation.user));
|
||||
field.html(user).addClass('annotator-user');
|
||||
} else {
|
||||
field.remove();
|
||||
}
|
||||
if (controls) {
|
||||
if (!this.authorize('update', annotation)) {
|
||||
controls.hideEdit();
|
||||
}
|
||||
if (!this.authorize('delete', annotation)) {
|
||||
return controls.hideDelete();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Permissions.prototype._setAuthFromToken = function(token) {
|
||||
return this.setUser(token.userId);
|
||||
};
|
||||
|
||||
return Permissions;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=permissions.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "permissions.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/permissions.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAcA,IAAA;;kSAAA;;AAAM,CAAN,KAAsB,GAAP;CAIb;;CAAA,EACE,GADF;CACE,CAA2B,EAA3B,mBAAA,EAAA;CADF,GAAA;;CAAA,EAOE,IAHF;CAGE,CAA6B,EAA7B,uBAAA;CAAA,CAG6B,EAA7B,uBAAA;CAHA,CAYQ,CAAA,CAAR,EAAA,GAAS;CAAD,YAAU;CAZlB,IAYQ;CAZR,CAqBY,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A,GAAA,IAAA;AAC+B,CAA7B,CAAsD,EAAtD,EAAA,EAA6B,CAAA,CAAA;CAA7B,OAAA;QAAA;AAC6B,CAA7B,CAAsD,EAAtD,EAAA,EAA6B,CAAA,CAAA;CAApB,OAAD,EAAR,KAAA;QAFF;MAVY;CAvRd,EAuRc;;CAvRd,EA0SmB,EAAA,IAAC,QAApB;CACO,GAAD,CAAc,CAAlB,CAAA,IAAA;CA3SF,EA0SmB;;CA1SnB;;CAJyC,QAAS"
|
||||
}
|
|
@ -1,271 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
Annotator.Plugin.Store = (function(_super) {
|
||||
__extends(Store, _super);
|
||||
|
||||
Store.prototype.events = {
|
||||
'annotationCreated': 'annotationCreated',
|
||||
'annotationDeleted': 'annotationDeleted',
|
||||
'annotationUpdated': 'annotationUpdated'
|
||||
};
|
||||
|
||||
Store.prototype.options = {
|
||||
annotationData: {},
|
||||
emulateHTTP: false,
|
||||
loadFromSearch: false,
|
||||
prefix: '/store',
|
||||
urls: {
|
||||
create: '/annotations',
|
||||
read: '/annotations/:id',
|
||||
update: '/annotations/:id',
|
||||
destroy: '/annotations/:id',
|
||||
search: '/search'
|
||||
}
|
||||
};
|
||||
|
||||
function Store(element, options) {
|
||||
this._onError = __bind(this._onError, this);
|
||||
this._onLoadAnnotationsFromSearch = __bind(this._onLoadAnnotationsFromSearch, this);
|
||||
this._onLoadAnnotations = __bind(this._onLoadAnnotations, this);
|
||||
this._getAnnotations = __bind(this._getAnnotations, this);
|
||||
Store.__super__.constructor.apply(this, arguments);
|
||||
this.annotations = [];
|
||||
}
|
||||
|
||||
Store.prototype.pluginInit = function() {
|
||||
if (!Annotator.supported()) {
|
||||
return;
|
||||
}
|
||||
if (this.annotator.plugins.Auth) {
|
||||
return this.annotator.plugins.Auth.withToken(this._getAnnotations);
|
||||
} else {
|
||||
return this._getAnnotations();
|
||||
}
|
||||
};
|
||||
|
||||
Store.prototype._getAnnotations = function() {
|
||||
if (this.options.loadFromSearch) {
|
||||
return this.loadAnnotationsFromSearch(this.options.loadFromSearch);
|
||||
} else {
|
||||
return this.loadAnnotations();
|
||||
}
|
||||
};
|
||||
|
||||
Store.prototype.annotationCreated = function(annotation) {
|
||||
var _this = this;
|
||||
if (__indexOf.call(this.annotations, annotation) < 0) {
|
||||
this.registerAnnotation(annotation);
|
||||
return this._apiRequest('create', annotation, function(data) {
|
||||
if (data.id == null) {
|
||||
console.warn(Annotator._t("Warning: No ID returned from server for annotation "), annotation);
|
||||
}
|
||||
return _this.updateAnnotation(annotation, data);
|
||||
});
|
||||
} else {
|
||||
return this.updateAnnotation(annotation, {});
|
||||
}
|
||||
};
|
||||
|
||||
Store.prototype.annotationUpdated = function(annotation) {
|
||||
var _this = this;
|
||||
if (__indexOf.call(this.annotations, annotation) >= 0) {
|
||||
return this._apiRequest('update', annotation, (function(data) {
|
||||
return _this.updateAnnotation(annotation, data);
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
Store.prototype.annotationDeleted = function(annotation) {
|
||||
var _this = this;
|
||||
if (__indexOf.call(this.annotations, annotation) >= 0) {
|
||||
return this._apiRequest('destroy', annotation, (function() {
|
||||
return _this.unregisterAnnotation(annotation);
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
Store.prototype.registerAnnotation = function(annotation) {
|
||||
return this.annotations.push(annotation);
|
||||
};
|
||||
|
||||
Store.prototype.unregisterAnnotation = function(annotation) {
|
||||
return this.annotations.splice(this.annotations.indexOf(annotation), 1);
|
||||
};
|
||||
|
||||
Store.prototype.updateAnnotation = function(annotation, data) {
|
||||
if (__indexOf.call(this.annotations, annotation) < 0) {
|
||||
console.error(Annotator._t("Trying to update unregistered annotation!"));
|
||||
} else {
|
||||
$.extend(annotation, data);
|
||||
}
|
||||
return $(annotation.highlights).data('annotation', annotation);
|
||||
};
|
||||
|
||||
Store.prototype.loadAnnotations = function() {
|
||||
return this._apiRequest('read', null, this._onLoadAnnotations);
|
||||
};
|
||||
|
||||
Store.prototype._onLoadAnnotations = function(data) {
|
||||
var a, annotation, annotationMap, newData, _i, _j, _len, _len1, _ref;
|
||||
if (data == null) {
|
||||
data = [];
|
||||
}
|
||||
annotationMap = {};
|
||||
_ref = this.annotations;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
a = _ref[_i];
|
||||
annotationMap[a.id] = a;
|
||||
}
|
||||
newData = [];
|
||||
for (_j = 0, _len1 = data.length; _j < _len1; _j++) {
|
||||
a = data[_j];
|
||||
if (annotationMap[a.id]) {
|
||||
annotation = annotationMap[a.id];
|
||||
this.updateAnnotation(annotation, a);
|
||||
} else {
|
||||
newData.push(a);
|
||||
}
|
||||
}
|
||||
this.annotations = this.annotations.concat(newData);
|
||||
return this.annotator.loadAnnotations(newData.slice());
|
||||
};
|
||||
|
||||
Store.prototype.loadAnnotationsFromSearch = function(searchOptions) {
|
||||
return this._apiRequest('search', searchOptions, this._onLoadAnnotationsFromSearch);
|
||||
};
|
||||
|
||||
Store.prototype._onLoadAnnotationsFromSearch = function(data) {
|
||||
if (data == null) {
|
||||
data = {};
|
||||
}
|
||||
return this._onLoadAnnotations(data.rows || []);
|
||||
};
|
||||
|
||||
Store.prototype.dumpAnnotations = function() {
|
||||
var ann, _i, _len, _ref, _results;
|
||||
_ref = this.annotations;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
ann = _ref[_i];
|
||||
_results.push(JSON.parse(this._dataFor(ann)));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Store.prototype._apiRequest = function(action, obj, onSuccess) {
|
||||
var id, options, request, url;
|
||||
id = obj && obj.id;
|
||||
url = this._urlFor(action, id);
|
||||
options = this._apiRequestOptions(action, obj, onSuccess);
|
||||
request = $.ajax(url, options);
|
||||
request._id = id;
|
||||
request._action = action;
|
||||
return request;
|
||||
};
|
||||
|
||||
Store.prototype._apiRequestOptions = function(action, obj, onSuccess) {
|
||||
var data, method, opts;
|
||||
method = this._methodFor(action);
|
||||
opts = {
|
||||
type: method,
|
||||
headers: this.element.data('annotator:headers'),
|
||||
dataType: "json",
|
||||
success: onSuccess || function() {},
|
||||
error: this._onError
|
||||
};
|
||||
if (this.options.emulateHTTP && (method === 'PUT' || method === 'DELETE')) {
|
||||
opts.headers = $.extend(opts.headers, {
|
||||
'X-HTTP-Method-Override': method
|
||||
});
|
||||
opts.type = 'POST';
|
||||
}
|
||||
if (action === "search") {
|
||||
opts = $.extend(opts, {
|
||||
data: obj
|
||||
});
|
||||
return opts;
|
||||
}
|
||||
data = obj && this._dataFor(obj);
|
||||
if (this.options.emulateJSON) {
|
||||
opts.data = {
|
||||
json: data
|
||||
};
|
||||
if (this.options.emulateHTTP) {
|
||||
opts.data._method = method;
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
opts = $.extend(opts, {
|
||||
data: data,
|
||||
contentType: "application/json; charset=utf-8"
|
||||
});
|
||||
return opts;
|
||||
};
|
||||
|
||||
Store.prototype._urlFor = function(action, id) {
|
||||
var url;
|
||||
url = this.options.prefix != null ? this.options.prefix : '';
|
||||
url += this.options.urls[action];
|
||||
url = url.replace(/\/:id/, id != null ? '/' + id : '');
|
||||
url = url.replace(/:id/, id != null ? id : '');
|
||||
return url;
|
||||
};
|
||||
|
||||
Store.prototype._methodFor = function(action) {
|
||||
var table;
|
||||
table = {
|
||||
'create': 'POST',
|
||||
'read': 'GET',
|
||||
'update': 'PUT',
|
||||
'destroy': 'DELETE',
|
||||
'search': 'GET'
|
||||
};
|
||||
return table[action];
|
||||
};
|
||||
|
||||
Store.prototype._dataFor = function(annotation) {
|
||||
var data, highlights;
|
||||
highlights = annotation.highlights;
|
||||
delete annotation.highlights;
|
||||
$.extend(annotation, this.options.annotationData);
|
||||
data = JSON.stringify(annotation);
|
||||
if (highlights) {
|
||||
annotation.highlights = highlights;
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
Store.prototype._onError = function(xhr) {
|
||||
var action, message;
|
||||
action = xhr._action;
|
||||
message = Annotator._t("Sorry we could not ") + action + Annotator._t(" this annotation");
|
||||
if (xhr._action === 'search') {
|
||||
message = Annotator._t("Sorry we could not search the store for annotations");
|
||||
} else if (xhr._action === 'read' && !xhr._id) {
|
||||
message = Annotator._t("Sorry we could not ") + action + Annotator._t(" the annotations from the store");
|
||||
}
|
||||
switch (xhr.status) {
|
||||
case 401:
|
||||
message = Annotator._t("Sorry you are not allowed to ") + action + Annotator._t(" this annotation");
|
||||
break;
|
||||
case 404:
|
||||
message = Annotator._t("Sorry we could not connect to the annotations store");
|
||||
break;
|
||||
case 500:
|
||||
message = Annotator._t("Sorry something went wrong with the annotation store");
|
||||
}
|
||||
Annotator.showNotification(message, Annotator.Notification.ERROR);
|
||||
return console.error(Annotator._t("API request failed:") + (" '" + xhr.status + "'"));
|
||||
};
|
||||
|
||||
return Store;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=store.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "store.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/store.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAiBA,IAAA;;;wJAAA;;AAAM,CAAN,KAAsB,GAAP;CAKb;;CAAA,EACE,GADF;CACE,CAAqB,EAArB,eAAA;CAAA,CACqB,EAArB,eAAA;CADA,CAEqB,EAArB,eAAA;CAHF,GAAA;;CAAA,EAU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CApcF,EAsbU;;CAtbV,EA4cU,KAAV,CAAW;CACT,OAAA,OAAA;CAAA,EAAU,CAAV,EAAA,CAAA;CAAA,CACU,CAAA,CAAV,EAAU,CAAV,EAAmB,SAAsC,GAA/C;CAEV,EAAM,CAAN,CAAkB,EAAf,CAAH;CACE,CAAU,CAAA,GAAV,CAAA,EAAmB,4CAAT;AACsB,CAAtB,EAAD,CAAH,CAAe,CAFvB,CAEQ;CACN,CAAU,CAAA,GAAV,CAAA,EAAmB,YAAT,YAA+C;MAN3D;CAQA,EAAU,GAAV,MAAO;CAAP,EAAA,QACO;CAAS,CAAU,CAAA,GAAA,CAAV,CAAA,CAAmB,SAAgD,aAAzD;CAAnB;CADP,EAAA,QAEO;CAAS,CAAU,CAAA,IAAV,CAAA,CAAmB,4CAAT;CAAnB;CAFP,EAAA,QAGO;CAAS,CAAU,CAAA,IAAV,CAAA,CAAmB,6CAAT;CAH1B,IARA;CAAA,CAaoC,EAApC,CAAA,EAAA,EAAS,GAAiD,IAA1D;CAEQ,CAAM,CAAsC,CAAC,CAArD,CAAqD,CAA9C,EAAgB,EAAvB,UAAc;CA5dhB,EA4cU;;CA5cV;;CALmC,QAAS"
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var _ref,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Plugin.Tags = (function(_super) {
|
||||
__extends(Tags, _super);
|
||||
|
||||
function Tags() {
|
||||
this.setAnnotationTags = __bind(this.setAnnotationTags, this);
|
||||
this.updateField = __bind(this.updateField, this);
|
||||
_ref = Tags.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
Tags.prototype.options = {
|
||||
parseTags: function(string) {
|
||||
var tags;
|
||||
string = $.trim(string);
|
||||
tags = [];
|
||||
if (string) {
|
||||
tags = string.split(/\s+/);
|
||||
}
|
||||
return tags;
|
||||
},
|
||||
stringifyTags: function(array) {
|
||||
return array.join(" ");
|
||||
}
|
||||
};
|
||||
|
||||
Tags.prototype.field = null;
|
||||
|
||||
Tags.prototype.input = null;
|
||||
|
||||
Tags.prototype.pluginInit = function() {
|
||||
if (!Annotator.supported()) {
|
||||
return;
|
||||
}
|
||||
this.field = this.annotator.editor.addField({
|
||||
label: Annotator._t('Add some tags here') + '\u2026',
|
||||
load: this.updateField,
|
||||
submit: this.setAnnotationTags
|
||||
});
|
||||
this.annotator.viewer.addField({
|
||||
load: this.updateViewer
|
||||
});
|
||||
if (this.annotator.plugins.Filter) {
|
||||
this.annotator.plugins.Filter.addFilter({
|
||||
label: Annotator._t('Tag'),
|
||||
property: 'tags',
|
||||
isFiltered: Annotator.Plugin.Tags.filterCallback
|
||||
});
|
||||
}
|
||||
return this.input = $(this.field).find(':input');
|
||||
};
|
||||
|
||||
Tags.prototype.parseTags = function(string) {
|
||||
return this.options.parseTags(string);
|
||||
};
|
||||
|
||||
Tags.prototype.stringifyTags = function(array) {
|
||||
return this.options.stringifyTags(array);
|
||||
};
|
||||
|
||||
Tags.prototype.updateField = function(field, annotation) {
|
||||
var value;
|
||||
value = '';
|
||||
if (annotation.tags) {
|
||||
value = this.stringifyTags(annotation.tags);
|
||||
}
|
||||
return this.input.val(value);
|
||||
};
|
||||
|
||||
Tags.prototype.setAnnotationTags = function(field, annotation) {
|
||||
return annotation.tags = this.parseTags(this.input.val());
|
||||
};
|
||||
|
||||
Tags.prototype.updateViewer = function(field, annotation) {
|
||||
field = $(field);
|
||||
if (annotation.tags && $.isArray(annotation.tags) && annotation.tags.length) {
|
||||
return field.addClass('annotator-tags').html(function() {
|
||||
var string;
|
||||
return string = $.map(annotation.tags, function(tag) {
|
||||
return '<span class="annotator-tag">' + Annotator.Util.escape(tag) + '</span>';
|
||||
}).join(' ');
|
||||
});
|
||||
} else {
|
||||
return field.remove();
|
||||
}
|
||||
};
|
||||
|
||||
return Tags;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
Annotator.Plugin.Tags.filterCallback = function(input, tags) {
|
||||
var keyword, keywords, matches, tag, _i, _j, _len, _len1;
|
||||
if (tags == null) {
|
||||
tags = [];
|
||||
}
|
||||
matches = 0;
|
||||
keywords = [];
|
||||
if (input) {
|
||||
keywords = input.split(/\s+/g);
|
||||
for (_i = 0, _len = keywords.length; _i < _len; _i++) {
|
||||
keyword = keywords[_i];
|
||||
if (tags.length) {
|
||||
for (_j = 0, _len1 = tags.length; _j < _len1; _j++) {
|
||||
tag = tags[_j];
|
||||
if (tag.indexOf(keyword) !== -1) {
|
||||
matches += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return matches === keywords.length;
|
||||
};
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=tags.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "tags.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/tags.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAEA,IAAA;GAAA;;kSAAA;;AAAM,CAAN,KAAsB,GAAP;CAEb;;;;;;;CAAA;;CAAA,EAIE,IAJF;CAIE,CAAW,CAAA,CAAX,EAAW,GAAX;CACE,GAAA,MAAA;CAAA,EAAS,CAAA,EAAT;CAAA,CAAA,CAEO,CAAP,EAAA;CACA,GAA8B,EAA9B;CAAA,EAAO,CAAP,CAAO,CAAM,EAAb;QAHA;CADS,YAKT;CALF,IAAW;CAAX,CASe,CAAA,CAAf,CAAe,IAAC,IAAhB;CACQ,EAAN,CAAA,CAAK,QAAL;CAVF,IASe;CAbjB,GAAA;;CAAA,EAkBO,CAlBP,CAkBA;;CAlBA,EAsBO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AA;CAAU,CAAqB,CAAtB,CAAA,EAAT,GAAgC,CAAP,KAAzB;CAC+C,EAAV,CAAc,EAAd,GAAS,QAA1C,aAAA;CADK,EAAA,CAAA,KAAsB;CADjC,MAAsC;MADxC;CAOQ,IAAD,CAAL,OAAA;MAVU;CA/Hd,EA+Hc;;CA/Hd;;CAFkC,QAAS;;AA0J7C,CA1JA,CA0J+C,CAAR,CAAlB,CAAkB,CAAvB,GAAP,KAAT;CACE,KAAA,8CAAA;;GADoD,CAAP;IAC7C;CAAA,CAAA,CAAW,IAAX;CAAA,CACA,CAAW,KAAX;CACA,CAAA,EAAG,CAAH;CACE,EAAW,CAAX,CAAgB,CAAL,EAAX;AACA,CAAA,QAAA,sCAAA;8BAAA;CAAkC,GAAL;AAC3B,CAAA,YAAA,gCAAA;0BAAA;AAA2D,CAArB,EAAD,CAAH,CAAwB,EAAxB;CAAlC,GAAW,GAAX,KAAA;YAAA;CAAA;QADF;CAAA,IAFF;IAFA;CAOoB,IAAT,EAAX,CAAmB,CAAnB;CARqC"
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var _ref,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Annotator.Plugin.Unsupported = (function(_super) {
|
||||
__extends(Unsupported, _super);
|
||||
|
||||
function Unsupported() {
|
||||
_ref = Unsupported.__super__.constructor.apply(this, arguments);
|
||||
return _ref;
|
||||
}
|
||||
|
||||
Unsupported.prototype.options = {
|
||||
message: Annotator._t("Sorry your current browser does not support the Annotator")
|
||||
};
|
||||
|
||||
Unsupported.prototype.pluginInit = function() {
|
||||
var _this = this;
|
||||
if (!Annotator.supported()) {
|
||||
return $(function() {
|
||||
Annotator.showNotification(_this.options.message);
|
||||
if ((window.XMLHttpRequest === void 0) && (ActiveXObject !== void 0)) {
|
||||
return $('html').addClass('ie6');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return Unsupported;
|
||||
|
||||
})(Annotator.Plugin);
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=unsupported.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "unsupported.js",
|
||||
"sourceRoot": "../..",
|
||||
"sources": [
|
||||
"src/plugin/unsupported.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAEA,IAAA;GAAA;kSAAA;;AAAM,CAAN,KAAsB,GAAP;CAEb;;;;;CAAA;;CAAA,EACE,IADF;CACE,CAAS,EAAT,GAAA,EAAkB,kDAAT;CADX,GAAA;;CAAA,EAOY,MAAA,CAAZ;CACE,OAAA,IAAA;AAAO,CAAP,GAAA,KAAgB;CACd,EAAE,MAAA,IAAF;CAEE,IAA4B,EAAO,CAAnC,CAAS,OAAT;CAIA,GAAG,CAA0B,CAAnB,EAAV,KAA6C,CAAzC;CACF,IAAA,CAAA,EAAA,SAAA;UAPF;CAAF,MAAE;MAFM;CAPZ,EAOY;;CAPZ;;CAFyC,QAAS"
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
/*
|
||||
** Annotator {{VERSION}}
|
||||
** https://github.com/okfn/annotator/
|
||||
**
|
||||
** Copyright 2012 {{AUTHORS}}.
|
||||
** Dual licensed under the MIT and GPLv3 licenses.
|
||||
** https://github.com/okfn/annotator/blob/master/LICENSE
|
||||
**
|
||||
** Built at: {{DATE}}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=preamble.map
|
||||
*/
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"file": "preamble.js",
|
||||
"sourceRoot": "..",
|
||||
"sources": [
|
||||
"src/preamble.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": ";AAAA;;;;;;;;;;CAAA;CAAA"
|
||||
}
|
|
@ -1,326 +0,0 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
var Range,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Range = {};
|
||||
|
||||
Range.sniff = function(r) {
|
||||
if (r.commonAncestorContainer != null) {
|
||||
return new Range.BrowserRange(r);
|
||||
} else if (typeof r.start === "string") {
|
||||
return new Range.SerializedRange(r);
|
||||
} else if (r.start && typeof r.start === "object") {
|
||||
return new Range.NormalizedRange(r);
|
||||
} else {
|
||||
console.error(_t("Could not sniff range type"));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Range.nodeFromXPath = function(xpath, root) {
|
||||
var customResolver, evaluateXPath, namespace, node, segment;
|
||||
if (root == null) {
|
||||
root = document;
|
||||
}
|
||||
this.document = root.ownerDocument || document;
|
||||
evaluateXPath = function(xp, nsResolver) {
|
||||
var exception;
|
||||
if (nsResolver == null) {
|
||||
nsResolver = null;
|
||||
}
|
||||
try {
|
||||
return this.document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
} catch (_error) {
|
||||
exception = _error;
|
||||
console.log("XPath evaluation failed.");
|
||||
console.log("Trying fallback...");
|
||||
return Util.nodeFromXPath(xp, root);
|
||||
}
|
||||
};
|
||||
if (!$.isXMLDoc(document.documentElement)) {
|
||||
return evaluateXPath(xpath);
|
||||
} else {
|
||||
customResolver = document.createNSResolver(document.ownerDocument === null ? document.documentElement : document.ownerDocument.documentElement);
|
||||
node = evaluateXPath(xpath, customResolver);
|
||||
if (!node) {
|
||||
xpath = ((function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = xpath.split('/');
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
segment = _ref[_i];
|
||||
if (segment && segment.indexOf(':') === -1) {
|
||||
_results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
|
||||
} else {
|
||||
_results.push(segment);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})()).join('/');
|
||||
namespace = document.lookupNamespaceURI(null);
|
||||
customResolver = function(ns) {
|
||||
if (ns === 'xhtml') {
|
||||
return namespace;
|
||||
} else {
|
||||
return document.documentElement.getAttribute('xmlns:' + ns);
|
||||
}
|
||||
};
|
||||
node = evaluateXPath(xpath, customResolver);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
Range.RangeError = (function(_super) {
|
||||
__extends(RangeError, _super);
|
||||
|
||||
function RangeError(type, message, parent) {
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
this.parent = parent != null ? parent : null;
|
||||
RangeError.__super__.constructor.call(this, this.message);
|
||||
}
|
||||
|
||||
return RangeError;
|
||||
|
||||
})(Error);
|
||||
|
||||
Range.BrowserRange = (function() {
|
||||
function BrowserRange(obj) {
|
||||
this.commonAncestorContainer = obj.commonAncestorContainer;
|
||||
this.startContainer = obj.startContainer;
|
||||
this.startOffset = obj.startOffset;
|
||||
this.endContainer = obj.endContainer;
|
||||
this.endOffset = obj.endOffset;
|
||||
}
|
||||
|
||||
BrowserRange.prototype.normalize = function(root) {
|
||||
var it, node, nr, offset, p, r, _i, _len, _ref;
|
||||
if (this.tainted) {
|
||||
console.error(_t("You may only call normalize() once on a BrowserRange!"));
|
||||
return false;
|
||||
} else {
|
||||
this.tainted = true;
|
||||
}
|
||||
r = {};
|
||||
nr = {};
|
||||
_ref = ['start', 'end'];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
p = _ref[_i];
|
||||
node = this[p + 'Container'];
|
||||
offset = this[p + 'Offset'];
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
it = node.childNodes[offset];
|
||||
node = it || node.childNodes[offset - 1];
|
||||
if (node.nodeType === Node.ELEMENT_NODE && !node.firstChild) {
|
||||
it = null;
|
||||
node = node.previousSibling;
|
||||
}
|
||||
while (node.nodeType !== Node.TEXT_NODE) {
|
||||
node = node.firstChild;
|
||||
}
|
||||
offset = it ? 0 : node.nodeValue.length;
|
||||
}
|
||||
r[p] = node;
|
||||
r[p + 'Offset'] = offset;
|
||||
}
|
||||
nr.start = r.startOffset > 0 ? r.start.splitText(r.startOffset) : r.start;
|
||||
if (r.start === r.end) {
|
||||
if ((r.endOffset - r.startOffset) < nr.start.nodeValue.length) {
|
||||
nr.start.splitText(r.endOffset - r.startOffset);
|
||||
}
|
||||
nr.end = nr.start;
|
||||
} else {
|
||||
if (r.endOffset < r.end.nodeValue.length) {
|
||||
r.end.splitText(r.endOffset);
|
||||
}
|
||||
nr.end = r.end;
|
||||
}
|
||||
nr.commonAncestor = this.commonAncestorContainer;
|
||||
while (nr.commonAncestor.nodeType !== Node.ELEMENT_NODE) {
|
||||
nr.commonAncestor = nr.commonAncestor.parentNode;
|
||||
}
|
||||
return new Range.NormalizedRange(nr);
|
||||
};
|
||||
|
||||
BrowserRange.prototype.serialize = function(root, ignoreSelector) {
|
||||
return this.normalize(root).serialize(root, ignoreSelector);
|
||||
};
|
||||
|
||||
return BrowserRange;
|
||||
|
||||
})();
|
||||
|
||||
Range.NormalizedRange = (function() {
|
||||
function NormalizedRange(obj) {
|
||||
this.commonAncestor = obj.commonAncestor;
|
||||
this.start = obj.start;
|
||||
this.end = obj.end;
|
||||
}
|
||||
|
||||
NormalizedRange.prototype.normalize = function(root) {
|
||||
return this;
|
||||
};
|
||||
|
||||
NormalizedRange.prototype.limit = function(bounds) {
|
||||
var nodes, parent, startParents, _i, _len, _ref;
|
||||
nodes = $.grep(this.textNodes(), function(node) {
|
||||
return node.parentNode === bounds || $.contains(bounds, node.parentNode);
|
||||
});
|
||||
if (!nodes.length) {
|
||||
return null;
|
||||
}
|
||||
this.start = nodes[0];
|
||||
this.end = nodes[nodes.length - 1];
|
||||
startParents = $(this.start).parents();
|
||||
_ref = $(this.end).parents();
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
parent = _ref[_i];
|
||||
if (startParents.index(parent) !== -1) {
|
||||
this.commonAncestor = parent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
NormalizedRange.prototype.serialize = function(root, ignoreSelector) {
|
||||
var end, serialization, start;
|
||||
serialization = function(node, isEnd) {
|
||||
var n, nodes, offset, origParent, textNodes, xpath, _i, _len;
|
||||
if (ignoreSelector) {
|
||||
origParent = $(node).parents(":not(" + ignoreSelector + ")").eq(0);
|
||||
} else {
|
||||
origParent = $(node).parent();
|
||||
}
|
||||
xpath = Util.xpathFromNode(origParent, root)[0];
|
||||
textNodes = Util.getTextNodes(origParent);
|
||||
nodes = textNodes.slice(0, textNodes.index(node));
|
||||
offset = 0;
|
||||
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
||||
n = nodes[_i];
|
||||
offset += n.nodeValue.length;
|
||||
}
|
||||
if (isEnd) {
|
||||
return [xpath, offset + node.nodeValue.length];
|
||||
} else {
|
||||
return [xpath, offset];
|
||||
}
|
||||
};
|
||||
start = serialization(this.start);
|
||||
end = serialization(this.end, true);
|
||||
return new Range.SerializedRange({
|
||||
start: start[0],
|
||||
end: end[0],
|
||||
startOffset: start[1],
|
||||
endOffset: end[1]
|
||||
});
|
||||
};
|
||||
|
||||
NormalizedRange.prototype.text = function() {
|
||||
var node;
|
||||
return ((function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = this.textNodes();
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
node = _ref[_i];
|
||||
_results.push(node.nodeValue);
|
||||
}
|
||||
return _results;
|
||||
}).call(this)).join('');
|
||||
};
|
||||
|
||||
NormalizedRange.prototype.textNodes = function() {
|
||||
var end, start, textNodes, _ref;
|
||||
textNodes = Util.getTextNodes($(this.commonAncestor));
|
||||
_ref = [textNodes.index(this.start), textNodes.index(this.end)], start = _ref[0], end = _ref[1];
|
||||
return $.makeArray(textNodes.slice(start, +end + 1 || 9e9));
|
||||
};
|
||||
|
||||
NormalizedRange.prototype.toRange = function() {
|
||||
var range;
|
||||
range = document.createRange();
|
||||
range.setStartBefore(this.start);
|
||||
range.setEndAfter(this.end);
|
||||
return range;
|
||||
};
|
||||
|
||||
return NormalizedRange;
|
||||
|
||||
})();
|
||||
|
||||
Range.SerializedRange = (function() {
|
||||
function SerializedRange(obj) {
|
||||
this.start = obj.start;
|
||||
this.startOffset = obj.startOffset;
|
||||
this.end = obj.end;
|
||||
this.endOffset = obj.endOffset;
|
||||
}
|
||||
|
||||
SerializedRange.prototype.normalize = function(root) {
|
||||
var contains, e, length, node, p, range, tn, _i, _j, _len, _len1, _ref, _ref1;
|
||||
range = {};
|
||||
_ref = ['start', 'end'];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
p = _ref[_i];
|
||||
try {
|
||||
node = Range.nodeFromXPath(this[p], root);
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
throw new Range.RangeError(p, ("Error while finding " + p + " node: " + this[p] + ": ") + e, e);
|
||||
}
|
||||
if (!node) {
|
||||
throw new Range.RangeError(p, "Couldn't find " + p + " node: " + this[p]);
|
||||
}
|
||||
length = 0;
|
||||
_ref1 = Util.getTextNodes($(node));
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
tn = _ref1[_j];
|
||||
if (length + tn.nodeValue.length >= this[p + 'Offset']) {
|
||||
range[p + 'Container'] = tn;
|
||||
range[p + 'Offset'] = this[p + 'Offset'] - length;
|
||||
break;
|
||||
} else {
|
||||
length += tn.nodeValue.length;
|
||||
}
|
||||
}
|
||||
if (range[p + 'Offset'] == null) {
|
||||
throw new Range.RangeError("" + p + "offset", "Couldn't find offset " + this[p + 'Offset'] + " in element " + this[p]);
|
||||
}
|
||||
}
|
||||
contains = document.compareDocumentPosition == null ? function(a, b) {
|
||||
return a.contains(b);
|
||||
} : function(a, b) {
|
||||
return a.compareDocumentPosition(b) & 16;
|
||||
};
|
||||
$(range.startContainer).parents().each(function() {
|
||||
if (contains(this, range.endContainer)) {
|
||||
range.commonAncestorContainer = this;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return new Range.BrowserRange(range).normalize(root);
|
||||
};
|
||||
|
||||
SerializedRange.prototype.serialize = function(root, ignoreSelector) {
|
||||
return this.normalize(root).serialize(root, ignoreSelector);
|
||||
};
|
||||
|
||||
SerializedRange.prototype.toObject = function() {
|
||||
return {
|
||||
start: this.start,
|
||||
startOffset: this.startOffset,
|
||||
end: this.end,
|
||||
endOffset: this.endOffset
|
||||
};
|
||||
};
|
||||
|
||||
return SerializedRange;
|
||||
|
||||
})();
|
||||
|
||||
/*
|
||||
//@ sourceMappingURL=range.map
|
||||
*/
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue