Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
47bce37
moving EPUB3 Multiple Rendition code into shared-js (for reuse in nat…
danielweck Feb 16, 2015
22b4513
typo
danielweck Feb 16, 2015
3b27251
updates to EPUB3 Multiple Renditions object (raw data)
danielweck Feb 16, 2015
55ae3ab
fixes to EPUB3 Multiple Renditions (now working fine, in both zipped …
danielweck Feb 16, 2015
8496475
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Mar 23, 2015
9c618e9
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Jul 7, 2015
bfb18d1
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Jul 12, 2015
b6af3a6
AMD-ify Multiple Renditions
danielweck Jul 12, 2015
99f0c64
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Sep 11, 2015
233aebb
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Sep 28, 2015
0e209e3
updated build
danielweck Sep 28, 2015
bc9f601
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Nov 19, 2015
a7865d7
4x spaces indentation instead of tab character
danielweck Nov 19, 2015
5bdd479
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Dec 8, 2015
0ff24d8
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Jan 15, 2016
41a6be0
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Feb 11, 2016
2fa3d75
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Mar 8, 2016
e56ec36
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Apr 26, 2016
a283bf0
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Aug 16, 2016
b1f61dd
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Jan 15, 2017
b45ede6
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck May 25, 2017
39d4eaa
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Jun 8, 2017
de4e4c8
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Jun 19, 2017
767fb7a
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Apr 5, 2018
eb3a078
Merge branch 'develop' into feature/epub3MultipleRenditions
danielweck Aug 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 250 additions & 3 deletions build-output/_multiple-bundles/readium-shared-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -21349,6 +21349,231 @@ define('readium_shared_js/views/external_agent_support',["../globals", "undersco
return ExternalAgentSupport;
});

// Created by Daniel Weck.
// Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
// 3. Neither the name of the organization nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.

/**
* Mapping Data, see http://www.idpf.org/epub/renditions/multiple/#h.o54dzjuwr54c
*
* @typedef {object} ReadiumSDK.Models.MappingData
* @property string href - the original a@href attribute
* @property string rendition - the original a@epub:rendition attribute (may be undefined)
* @property string cfiFull - the entire CFI expression given in href (applies to the OPF itself)
* @property string cfiPartial - only the part of the CFI expression that applies to the spine item
* @property string opf - the resolved rendition absolute path (e.g. "/EPUB/package.opf")
* @property string target - the resolved spine item absolute path (e.g. "/EPUB/html/chapter1.xhtml")
* @property string idref - the resolved idref of the spine item (i.e. spine>itemref@idref attribute)
*/

/**
* Rendition Data
*
* @typedef {object} ReadiumSDK.Models.RenditionData
* @property string Media - CSS Media Query, see rendition:media http://www.idpf.org/epub/renditions/multiple/#h.v5umqueir7kw
* @property string Layout - reflowable or pre-paginated, see rendition:layout http://www.idpf.org/epub/renditions/multiple/#h.652no7qrkqt9
* @property string Language - lang tag, see rendition:language http://www.idpf.org/epub/renditions/multiple/#h.i2sz2e7fiql8
* @property string AccessMode - auditory, tactile, textual, visual, see rendition:accessMode http://www.idpf.org/epub/renditions/multiple/#h.u174vaicigpv
* @property string Label - description, see rendition:laberl http://www.idpf.org/epub/renditions/multiple/#h.t1refnod0o2
*/

/**
* Multiple Renditions Data
*
* @typedef {object} ReadiumSDK.Models.MultipleRenditionsData
* @property [{ReadiumSDK.Models.RenditionData}] renditions - array of rendition objects
* @property integer selectedIndex - index of currently-selected item in the renditions array
* @property [[{ReadiumSDK.Models.MappingData}]] mappings - array of arrays of mapping objects (top array stores each UL list container present in nav@epub:type=resource-map, and sub-arrays store actual list items (equivalent locations in different OPF renditions)) see http://www.idpf.org/epub/renditions/multiple/#h.o54dzjuwr54c
*/

define('readium_shared_js/models/multiple_renditions',[], function() {

/**
* EPUB3 Multiple Renditions, see http://www.idpf.org/epub/renditions/multiple
* @class ReadiumSDK.Models.MultipleRenditions
* @param {ReadiumSDK.Models.MultipleRenditionsData} multipleRenditions
* @constructor
*/
var MultipleRenditions = function(multipleRenditions) {

var self = this;

/**
* @see {ReadiumSDK.Models.MultipleRenditionsData}
*/
this.renditions = multipleRenditions ? multipleRenditions.renditions : undefined;
this.selectedIndex = multipleRenditions ? multipleRenditions.selectedIndex : -1;
this.mappings = multipleRenditions ? multipleRenditions.mappings : undefined;


var cfiTokenise = function(cfi) {
//console.log(cfi);
var arrayOfIndices = [];

var split = cfi.split("/");
for (var i = 0; i < split.length; i++) {
var token = split[i];
var j = token.indexOf("[");
if (j > 0) {
token = token.substr(0, token.length - j);
}
j = token.indexOf("@");
if (j > 0) {
token = token.substr(0, token.length - j);
}
if (!token.length) continue;

var index = parseInt(token);
//console.log(index);
arrayOfIndices.push(index);
}

return arrayOfIndices;
};

// cfi1 <= cfi2
var cfiIsBeforeOrEqual = function(cfi1, cfi2) {

var i = 0;
while (i < cfi1.length && i < cfi2.length) {
if (cfi1[i] > cfi2[i]) return false;
i++;
}

return true;
};


/**
* Get spine item data in readium-shared-js accepted format.
* @param openPageRequest the original page request
* @returns The unmodified openPageRequest parameter if the rendition OPF is the same, or the modified openPageRequest parameter if the rendition OPF was mapped succesfully, or undefined if the OPF could not be mapped.
*/
this.adjustPageRequestRenditionMapping = function(openPageRequest) {

if (!openPageRequest) return undefined;
if (!multipleRenditions || !openPageRequest.opfPath) return openPageRequest;

var rendition = multipleRenditions.renditions[multipleRenditions.selectedIndex];

if (rendition.opfPath == openPageRequest.opfPath) return openPageRequest;

if (!multipleRenditions.mappings) return undefined;

var nearestMapping = undefined;

console.log("ADJUSTING READING LOCATION");
console.debug(openPageRequest.elementCfi);

var cfi2 = cfiTokenise(openPageRequest.elementCfi);

for (var i = 0; i < multipleRenditions.mappings.length; i++) {
var mappingUL = multipleRenditions.mappings[i];

for (var j = 0; j < mappingUL.length; j++) {
var mapping = mappingUL[j];

if (openPageRequest.opfPath === mapping.opf && openPageRequest.idref === mapping.idref) {
var cfi1 = cfiTokenise(mapping.cfiPartial);
if (nearestMapping) {
var cfi3 = cfiTokenise(nearestMapping.cfiPartial);
if (cfiIsBeforeOrEqual(cfi1, cfi3)) {
break;
}
}
if (cfiIsBeforeOrEqual(cfi1, cfi2)) {

for (var k = 0; k < mappingUL.length; k++) {
var m = mappingUL[k];
if (rendition.opfPath === m.opf) {
nearestMapping = m;
break;
}
}

break;
}
}

//mapping.opf
//openPageRequest.opfPath

//mapping.idref
//openPageRequest.idref

//mapping.cfiPartial
//openPageRequest.elementCfi
}
}

if (nearestMapping) {
console.log("FOUND!");
console.debug(nearestMapping);
var elCfi = nearestMapping.cfiPartial;
var split = elCfi.split("/");
var lastIndex = split[split.length-1];
var l = lastIndex.indexOf("@");
if (l > 0) {
lastIndex = lastIndex.substr(0, lastIndex.length-l);
}

var isOdd = (lastIndex % 2) == 1;
if (isOdd) {
elCfi = "";
for (var k = 0; k < split.length-1; k++) {
var index = split[k];
if (!index.length) continue;
elCfi += ("/" + index);
}

console.debug("ODD: "+elCfi);
}

var l = elCfi.indexOf("@");
if (l < 0) {
elCfi += "@0:0";
}

openPageRequest.opfPath = nearestMapping.opf;
openPageRequest.idref = nearestMapping.idref;
openPageRequest.elementCfi = elCfi;

console.debug(JSON.stringify(openPageRequest));
} else {
console.log("RENDITION MAPPING NOT FOUND!");
openPageRequest = undefined;
}

return openPageRequest;
};
};

return MultipleRenditions;
});



// Created by Boris Schneiderman.
// Modified by Daniel Weck
// Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.
Expand Down Expand Up @@ -21378,11 +21603,11 @@ define('readium_shared_js/views/external_agent_support',["../globals", "undersco
define('readium_shared_js/views/reader_view',["../globals", "jquery", "underscore", "eventEmitter", "./fixed_view", "../helpers", "./iframe_loader", "./internal_links_support",
"./media_overlay_data_injector", "./media_overlay_player", "../models/package", "../models/metadata", "../models/page_open_request",
"./reflowable_view", "./scroll_view", "../models/style_collection", "../models/switches", "../models/trigger",
"../models/viewer_settings", "../models/bookmark_data", "../models/node_range_info", "./external_agent_support"],
"../models/viewer_settings", "../models/bookmark_data", "../models/node_range_info", "./external_agent_support", "../models/multiple_renditions"],
function (Globals, $, _, EventEmitter, FixedView, Helpers, IFrameLoader, InternalLinksSupport,
MediaOverlayDataInjector, MediaOverlayPlayer, Package, Metadata, PageOpenRequest,
ReflowableView, ScrollView, StyleCollection, Switches, Trigger,
ViewerSettings, BookmarkData, NodeRangeInfo, ExternalAgentSupport) {
ViewerSettings, BookmarkData, NodeRangeInfo, ExternalAgentSupport, MultipleRenditions) {
/**
* Options passed on the reader from the readium loader/initializer
*
Expand Down Expand Up @@ -21733,7 +21958,16 @@ var ReaderView = function (options) {
this.userStyles = function () {
return _userStyles;
};


/**
* Returns the EPUB3 Multiple Renditions data for the currently-opened ebook (initialised in this.openBook())
*
* @returns {ReadiumSDK.Models.MultipleRenditions} can be undefined
*/
this.getMultipleRenditions = function() {
return _multipleRenditions;
};

/**
* Open Book Data
*
Expand Down Expand Up @@ -21780,12 +22014,25 @@ var ReaderView = function (options) {
self.setStyles(openBookData.styles);
}

if (openBookData.multipleRenditions) {
_multipleRenditions = new MultipleRenditions(openBookData.multipleRenditions);
} else {
_multipleRenditions = undefined;
}

var pageRequestData = undefined;

if (openBookData.openPageRequest && typeof(openBookData.openPageRequest) === 'function') {
openBookData.openPageRequest = openBookData.openPageRequest();
}

if (openBookData.openPageRequest) {

if (_multipleRenditions) {
openBookData.openPageRequest = _multipleRenditions.adjustPageRequestRenditionMapping(openBookData.openPageRequest);
}
}

if (openBookData.openPageRequest) {

if (openBookData.openPageRequest.idref || (openBookData.openPageRequest.contentRefUrl && openBookData.openPageRequest.sourceFileHref)) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions build-output/_multiple-bundles/readium-shared-js.js.map

Large diffs are not rendered by default.

Loading