function FluidbookTabs(fluidbook) {
this.fluidbook = fluidbook;
+ this.hasSVGTabs = false;
if (this.fluidbook.datas.svgTabs) {
+ this.hasSVGTabs = true;
+ this.svgLoaded = false;
+ this.cont;
+ this.visibility = {};
+ this.naturalDimensions = {width: 0, height: 0};
this.init();
} else if (this.hasTabs()) {
this.initZip();
}
FluidbookTabs.prototype = {
-
hasTabs: function () {
return this.fluidbook.datas.tabsHTML5 !== '';
},
},
+ checkVisibility: function (types) {
+ var res = true;
+ var $this = this;
+ $.each(types, function (k, type) {
+ if ($this.visibility[type] === false) {
+ res = false;
+ return false;
+ }
+ });
+ return res;
+ },
+
+ guessTabsWidth: function (bookScale) {
+ var fh = this.fluidbook.datas.height * bookScale;
+ var tabsScale = fh / this.naturalDimensions.height;
+ return this.linkWidth * tabsScale;
+ },
+
+ guessBookScale: function (bookScale, aw, fww) {
+ if (!this.hasSVGTabs || !this.svgLoaded) {
+ this.changeVisibility('priority', true);
+ return 1;
+ }
+
+ if (this.checkVisibility(['portrait'/*, 'firstpage', 'lastpage'*/]) === false) {
+ this.changeVisibility('priority', true);
+ return 1;
+ }
+
+ var tabsWidth = this.guessTabsWidth(bookScale);
+ console.log(tabsWidth);
+ var awt = aw - (tabsWidth * 2);
+ var scale = awt / fww;
+ var ratio = (scale / bookScale);
+ var reductionRatio = 1 - ratio;
+
+ if (reductionRatio > this.priority) {
+ this.changeVisibility('priority', false);
+ return 1;
+ }
+ this.changeVisibility('priority', true);
+
+ return Math.min(1, ratio);
+ },
+
init: function () {
if ($("#background .links").length === 0) {
$("#background").append('<div class="links"></div>');
}
- $("#background .links").append('<div id="l_tabs" class="link tabslink multimedia" data-id="tabs"></div>');
+ this.setOptions();
+ $("#background .links").append('<div id="l_tabs" class="link tabslink multimedia ' + this.align + '" data-id="tabs"></div>');
this.element = $("#l_tabs");
- this.cont;
- this.visibility = {};
- this.naturalDimensions = {width: 0, height: 0};
- this.image = 'tabs.svg';
- this.setOptions();
+ this.addLinks(this.fluidbook.datas.tabsPages);
this.initTabs();
},
this.hideOnZoom = this.fluidbook.datas.tabsHideOnZoom;
this.hideWhenOverlapingArrows = this.fluidbook.datas.tabsHideWhenOverlapingArrows;
this.mode = 'side';
- this.align = this.fluidbook.datas.tabsSide;
+ this.side = this.align = this.fluidbook.datas.tabsSide;
this.margin = parseFloat(this.fluidbook.datas.tabsMargin);
this.hideEdge = this.fluidbook.datas.tabsHideEdges;
this.linkWidth = parseFloat(this.fluidbook.datas.tabsLinkWidth);
+ this.priority = parseFloat(this.fluidbook.datas.tabsPriority) / 100;
this.sections = this.fluidbook.datas.tabsSections.map(function (x) {
return parseInt(x);
});
- this.addLinks(this.fluidbook.datas.tabsPages);
+
},
addLinks: function (pages) {
value--;
}
$this.links.push({
- css: {height: (100 / nbPages) + '%', top: (100 / nbPages * i) + '%', width: $this.linkWidth},
+ css: {height: (100 / nbPages) + '%', top: (100 / nbPages * i) + '%'},
page: parseInt(value),
index: index,
id: 'o' + index
$this.naturalDimensions.height = Math.floor(parseFloat($(data).attr('height')));
$this.svg = $this.cont.find('svg');
$this.svg.addClass('tabsimg').css({height: '100%', width: 'auto'});
+ $this.svgLoaded = true;
$this.createLinks();
$this.initStandardEvents();
}, 'text');
hideEdges: function (hide) {
if (!hide) {
- $("#edges .edge").css('visibility', 'visible');
+ $("#edges .edge, #shadow .shadow.side").css('visibility', 'visible');
return;
}
if (this.hideEdge === undefined || this.hideEdge === 'none') {
createLinks: function () {
var $this = this;
+
+ var commoncss = {};
+ var widthPct = (100 * (this.linkWidth / this.naturalDimensions.width)) + "%";
+ commoncss.width = widthPct;
+
$(this.links).each(function (k, v) {
var l = $('<a class="tablink" />');
$this.cont.append(l);
+ l.css(commoncss);
l.css(v.css);
if (v.page) {
l.attr('href', '#/page/' + v.page);
if (this.hideOnPortrait) {
this.visibility.portrait = true;
$(this.fluidbook).on('fluidbook.resize.orientation', function (e, data) {
- if (data.orientation == 'portrait') {
+ if (data.orientation === 'portrait') {
$this.changeVisibility('portrait', false);
} else {
$this.changeVisibility('portrait', true);
}
this.cont.css(css);
-
- if (this.hideWhenOverlapingArrows) {
- try {
- var bbox = this.svg.find('#o1').get(0).getBoundingClientRect();
- if (this.align === 'left') {
- if (bbox.left < data.arrowLeftRect.right) {
- this.changeVisibility('arrows', false);
- } else {
- this.changeVisibility('arrows', true);
- }
- }
- } catch (e) {
-
- }
- }
},
};