aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzefanja <zefanja@freenet.de>2014-04-10 10:49:20 +0700
committerzefanja <zefanja@freenet.de>2014-04-10 10:49:20 +0700
commite7a960b5ff25da15f44923a7ad23514853cca6e0 (patch)
tree80db7fbe42e0cba73f002dea94e551301e4152e5
parent83cf27f8307387575db72fe20d4ee664a83fd1aa (diff)
downloadbiblez-ng-e7a960b5ff25da15f44923a7ad23514853cca6e0.tar.gz
* passage label will update on scrolling
* improved positioning when changing font-size or -style
-rw-r--r--source/kinds.js23
-rw-r--r--source/main.js133
2 files changed, 108 insertions, 48 deletions
diff --git a/source/kinds.js b/source/kinds.js
index 699ef0f..d0a7c2d 100644
--- a/source/kinds.js
+++ b/source/kinds.js
@@ -4,6 +4,9 @@ enyo.kind({
published: {
clientStyle: "display: inline;"
},
+ events: {
+ onOffset: ""
+ },
create: function () {
this.inherited(arguments);
@@ -13,6 +16,26 @@ enyo.kind({
clientStyleChanged: function () {
this.$.generator.setClientStyle(this.clientStyle);
+ },
+
+ generatePage: function() {
+ this.inherited(arguments);
+ //this.doOffset({offset: this.$.generator.getRowOffset(), rowSize: this.rowSize});
+ },
+
+ getRowSize: function () {
+ return this.rowSize;
+ },
+
+ reset: function (inIndex) {
+ this.getSelection().clear();
+ this.invalidateMetrics();
+ this.invalidatePages();
+ this.stabilize();
+ if(inIndex)
+ this.scrollToRow(inIndex + 1);
+ else
+ this.scrollToRow(1);
}
}); \ No newline at end of file
diff --git a/source/main.js b/source/main.js
index 37cae3d..548355d 100644
--- a/source/main.js
+++ b/source/main.js
@@ -110,15 +110,10 @@ enyo.kind({
settings: {id: "settings"},
footnotes: {},
verses: [],
- firstTop: true,
- firstBottom: true,
reachedTop: false,
reachedBottom: false,
- passagePos: {
- top: null,
- middle: null,
- bottom: null
- },
+ offset: 0,
+ rowSize: 0,
create: function () {
this.inherited(arguments);
@@ -233,7 +228,7 @@ enyo.kind({
this.$.bcSelector.setModule(this.currentModule);
//Load the verses
- if(this.passage === this.settings.lastRead)
+ if(this.passage === this.settings.lastRead || !this.settings.lastRead)
this.handlePassage();
if(this.settings)
this.setPassage((this.settings.lastRead) ? this.settings.lastRead : this.passage);
@@ -252,11 +247,25 @@ enyo.kind({
passageChanged: function (inSender, inEvent) {
this.$.bcPopup.hide();
- delete inEvent.originator;
- delete inEvent.delegate;
- delete inEvent.type;
- this.passage = inEvent;
- if (!this.reachedBottom && !this.reachedTop)
+ if (!inEvent.offsetRef) {
+ delete inEvent.originator;
+ delete inEvent.delegate;
+ delete inEvent.type;
+ this.passage = inEvent;
+ } else {
+ if (inEvent.offsetRef.hasOwnProperty("osisRef"))
+ this.passage = inEvent.offsetRef;
+ else {
+ inOsis = (inEvent.offsetRef.split(".").length > 2) ? inEvent.offsetRef.slice(0, inEvent.offsetRef.lastIndexOf(".")): inEvent.offsetRef;
+ this.passage = {
+ osisRef: inOsis,
+ label: inOsis.replace(".", " "),
+ chapter: parseInt(inOsis.split(".")[1], 10)
+ };
+ }
+
+ }
+ if (!this.reachedBottom && !this.reachedTop && !inEvent.offsetRef)
this.handlePassage();
//Persist current passage
@@ -294,7 +303,7 @@ enyo.kind({
this.footnotes = inResult.footnotes;
this.verses = inResult.verses;
this.handleUserData(this.passage.osisRef);
- this.verses.unshift({text: "<br><div class='caps'>" + this.passage.chapter + "</div>"});
+ this.verses.unshift({osisRef: this.passage.osisRef, text: "<br><div class='caps'>" + this.passage.chapter + "</div>"});
this.$.verseList.setCount(this.verses.length);
this.$.verseList.refresh();
if (verseNumber === 0)
@@ -342,6 +351,23 @@ enyo.kind({
return true;
},
+ handleListPosition: function (inSender, inEvent) {
+ var b = inEvent.scrollBounds;
+ if(b && b.top > 0 && this.verses.length !== 0) {
+ this.rowSize = this.$.verseList.getRowSize();
+ this.offset = Math.round(b.top / this.rowSize);
+ if (this.verses[this.offset] && this.verses[this.offset].osisRef) {
+ this.setPassage({offsetRef: this.verses[this.offset].osisRef});
+ }
+ }
+ /*if (this.verses[inEvent.offset] && this.verses[inEvent.offset].osisRef) {
+ this.setPassage({offsetRef: this.verses[inEvent.offset].osisRef});
+ this.offset = inEvent.offset;
+ }
+ console.log("OFFSET", this.offset); */
+ return true;
+ },
+
renderHistory: function (inSender, inEvent) {
this.$.historyMenu.destroyClientControls();
var hisItems = [];
@@ -464,7 +490,7 @@ enyo.kind({
handleFont: function (inSender, inEvent) {
this.$.verseList.applyStyle("font-family", inEvent.font);
- this.$.verseList.reset();
+ this.$.verseList.reset(this.offset);
api.putSetting("font", inEvent.font);
},
@@ -473,7 +499,7 @@ enyo.kind({
this.$.verseList.applyStyle("font-size", inEvent.fontSize + "em");
else
this.$.verseList.applyStyle("font-size", null);
- this.$.verseList.reset();
+ this.$.verseList.reset(this.offset);
api.putSetting("fontSize", inEvent.fontSize);
},
@@ -581,67 +607,78 @@ enyo.kind({
//handling infinite scrolling
handleScrolling: function (inSender, inEvent) {
- var cHeight = inEvent.scrollBounds.clientHeight,
- top = inEvent.scrollBounds.top,
- height = inEvent.scrollBounds.height,
- yDir = inEvent.scrollBounds.yDir;
-
- //console.log(cHeight, top, height, yDir);
-
- if(!this.reachedBottom && cHeight + top > height - 200/* && yDir === 1*/) {
- this.reachedBottom = true;
- //console.log("BOTTOM");
- this.addText(true, enyo.bind(this, function () {
- this.reachedBottom = false;
- }));
- } else if (!this.reachedTop && top < 30/* && yDir === -1*/) {
- this.reachedTop = true;
- //console.log("TOP");
- this.addText(false, enyo.bind(this, function () {
- this.reachedTop = false;
- }));
- }
+ if(this.verses.length !== 0) {
+ var b = inEvent.scrollBounds;
+ var cHeight = b.clientHeight,
+ top = b.top,
+ height = b.height,
+ yDir = b.yDir;
+
+ if(b && b.top > 0) {
+ this.rowSize = this.$.verseList.getRowSize();
+ this.offset = Math.round(b.top / this.rowSize);
+ if (this.verses[this.offset] && this.verses[this.offset].osisRef) {
+ this.setPassage({offsetRef: this.verses[this.offset].osisRef});
+ }
+ }
+
+ //console.log(cHeight, top, height, yDir);
+ if(!this.reachedBottom && cHeight + top > height - 200/* && yDir === 1*/) {
+ this.reachedBottom = true;
+ //console.log("BOTTOM");
+ this.addText(true, enyo.bind(this, function () {
+ this.reachedBottom = false;
+ }));
+ } else if (!this.reachedTop && top < 30/* && yDir === -1*/) {
+ this.reachedTop = true;
+ //console.log("TOP");
+ this.addText(false, enyo.bind(this, function () {
+ this.reachedTop = false;
+ }));
+ }
+ }
+ return true;
},
addText: function(inBottom, inCallback) {
- if(!this.currentModule) {
+ if(!this.currentModule || this.verses.length === 0) {
inCallback();
return;
}
if(inBottom === true) {
//Load next verses
- console.log(this.verses, this.verses[1].osisRef.slice(0,this.verses[1].osisRef.lastIndexOf(".")));
- this.setPassage(sword.verseKey.next(this.verses[this.verses.length-1].osisRef.slice(0,this.verses[this.verses.length-1].osisRef.lastIndexOf(".")), this.currentModule.config.Versification));
- console.log(this.passage);
- this.loadText(this.passage.osisRef, enyo.bind(this, function (inError, inResult) {
+ var next = sword.verseKey.next(this.verses[this.verses.length-1].osisRef.slice(0,this.verses[this.verses.length-1].osisRef.lastIndexOf(".")), this.currentModule.config.Versification);
+ //console.log("NEXT:", next);
+ this.loadText(next.osisRef, enyo.bind(this, function (inError, inResult) {
if(!inError) {
- this.verses.push({text: "<br><div class='caps'>" + this.passage.chapter + "</div>"});
+ this.verses.push({osisRef: next.osisRef, text: "<br><div class='caps'>" + next.chapter + "</div>"});
this.verses.push.apply(this.verses, inResult.verses);
if(inResult.hasOwnProperty("footnotes"))
this.footnotes = api.extend(this.footnotes, inResult.footnotes);
this.$.verseList.setCount(this.verses.length);
this.$.verseList.refresh();
- this.handleUserData(this.passage.osisRef);
+ this.handleUserData(next.osisRef);
} else {
this.handleError(inError.message);
}
inCallback();
}));
} else {
- this.setPassage(sword.verseKey.previous(this.verses[1].osisRef.slice(0,this.verses[1].osisRef.lastIndexOf(".")), this.currentModule.config.Versification));
- this.loadText(this.passage.osisRef, enyo.bind(this, function (inError, inResult) {
+ var previous = sword.verseKey.previous(this.verses[1].osisRef.slice(0,this.verses[1].osisRef.lastIndexOf(".")), this.currentModule.config.Versification);
+ //console.log("Previous:", previous);
+ this.loadText(previous.osisRef, enyo.bind(this, function (inError, inResult) {
if(!inError) {
if(inResult.hasOwnProperty("footnotes"))
this.footnotes = api.extend(this.footnotes, inResult.footnotes);
var l = inResult.verses.length;
inResult.verses.push.apply(inResult.verses, this.verses);
this.verses = inResult.verses;
- this.verses.unshift({text: "<br><div class='caps'>" + this.passage.chapter + "</div>"});
+ this.verses.unshift({osisRef: previous, text: "<br><div class='caps'>" + previous.chapter + "</div>"});
this.$.verseList.setCount(this.verses.length);
this.$.verseList.refresh();
this.$.verseList.scrollToRow(l+1);
- this.handleUserData(this.passage.osisRef);
+ this.handleUserData(previous.osisRef);
} else {
this.handleError(inError.message);
}
@@ -651,7 +688,7 @@ enyo.kind({
},
loadText: function (inOsis, inCallback) {
- console.log(inOsis, this.passagePos);
+ //console.log("LOADTEXT", inOsis);
this.$.tbSpinner.show();
this.$.topTB.resized();
this.currentModule.renderText(inOsis,