Skip to content

Commit

Permalink
Fix S2 text loading
Browse files Browse the repository at this point in the history
  • Loading branch information
blockspeiser committed May 29, 2015
1 parent 2f580fa commit edbd6d6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 35 deletions.
6 changes: 3 additions & 3 deletions static/css/s2.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ body {
width: 100%;
box-sizing: border-box;
font-size: 16px;
line-height: 1.4;
line-height: 1.6;
text-align: justify;
margin: 0 auto;
}
Expand Down Expand Up @@ -177,8 +177,8 @@ body {
display: table-cell;
vertical-align: middle;
}
.categoryFilterGroup {

.categoryFilterGroup:last-child {
border-bottom: 1px solid #CCC;
}
.categoryFilter {
text-transform: uppercase;
Expand Down
98 changes: 66 additions & 32 deletions templates/s2.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@
"tan": "#D3BE90",
"red": "#D86F6D",
"navy": "#222F4F",
"pink": "#D9C6D4"
"pink": "#D9C6D4",
"grape": "#7B426E",
"lightblue": "#95C6D2",
"darkgreen": "#095868"
};

sjs.categoryColors = {
"Commentary": sjs.palette.blue,
"Tanach" : sjs.palette.darkgreen,
"Midrash": sjs.palette.green,
"Mishnah": sjs.palette.lightblue,
"Talmud": sjs.palette.tan,
"Halakha": sjs.palette.red,
"Philosophy": sjs.palette.grape

};

Expand All @@ -45,23 +51,20 @@
cb(this._texts[ref]);
return this._texts[ref];
} else {
var url = "/api/texts/" + ref + "?commentary=0&context=1";
var url = "/api/texts/" + normRef(ref) + "?commentary=0&context=0";
$.getJSON(url, function(data) {
this._saveText(data);
cb(data);
}.bind(this));
}
},
textWithContext: function(ref, cb) {

},
_saveText: function(data) {
if ("error" in data) {
sjs.alert.message(data.error);
return;
}
this._texts[data.ref] = data;
if (data.ref != data.sectionRef) {
if (data.ref == data.sectionRef) {
this._splitTextSection(data);
}
},
Expand All @@ -71,11 +74,11 @@
var en = data.text;
var he = data.he;
var length = Math.max(en.length, he.length);
en.pad(length, "");
he.pad(length, "");
en = en.pad(length, "");
he = he.pad(length, "");

var start = data.textDepth == data.sections.length ? data.sections[data.textDepth] : 1;
for (var i = 0; i < en.length; i++) {
for (var i = 0; i < length; i++) {
var ref = data.ref + ":" + (i+start);
var segment_data = clone(data);
$.extend(segment_data, {
Expand Down Expand Up @@ -108,7 +111,7 @@
if (ref in this._links) {
cb(this._links[ref]);
} else {
var url = "/api/links/" + ref + "?with_text=0";
var url = "/api/links/" + normRef(ref) + "?with_text=0";
$.getJSON(url, function(data) {
if ("error" in data) {
sjs.alert.message(data.error);
Expand All @@ -126,7 +129,7 @@
if (ref in this._links) {
cb();
} else {
var url = "/api/links/" + ref + "?with_text=0";
var url = "/api/links/" + normRef(ref) + "?with_text=0";
$.getJSON(url, function(data) {
if ("error" in data) {
sjs.alert.message(data.error);
Expand Down Expand Up @@ -222,16 +225,16 @@
var ReaderApp = React.createClass({
getInitialState: function() {
return {
viewPosition: 0,
previousScrollTop: 0,
currentFilter: [],
recentFilters: [],
contents: [{type: "TextRange", ref: this.props.initialRef }]
}
},
componentDidMount: function() {
window.onpopstate = function(event) {
window.addEventListener("popstate", function(event) {
this.setState({contents: [event.state]});
}.bind(this);
}.bind(this));
},
componentDidUpdate: function() {
var current = this.state.contents.slice(-1)[0];
Expand All @@ -241,12 +244,15 @@
url += "?with=" + (this.state.currentFilter.length ? this.state.currentFilter[0] : "all");
}
history.pushState(current, current.ref, url);
console.log("pushing " + current.ref);
$(window).scrollTop(this.state.previousScrollTop);
}
},
handleScroll: function(e) {

},
showTextList: function(ref) {
this.state.contents.push({type: "TextList", ref: ref});
this.setState({contents: this.state.contents});
this.setState({contents: this.state.contents, previousScrollTop: $(window).scrollTop() });
},
showBaseText: function(ref) {
if (ref) {
Expand Down Expand Up @@ -298,9 +304,8 @@
);
}
}.bind(this));
var style = {left: this.state.viewPosition * 100 + "%"}
return (
<div id="readerApp" style={style}>{items}</div>
<div id="readerApp">{items}</div>
);
}
});
Expand Down Expand Up @@ -334,23 +339,18 @@
sjs.library.text(this.state.sref, this.loadText);
},
loadText: function(data) {
if (this.props.basetext && data.ref !== data.sectionRef) {
// Allows load basetexts at section level
this.props.showBaseText(data.sectionRef);
return;
}
var wrap = (typeof data.text == "string");
var en = wrap ? [data.text] : data.text;
var he = wrap ? [data.he] : data.he;

// Pad the shorter array to make stepping through them easier.
var length = Math.max(en.length, he.length);
en.pad(length, "");
he.pad(length, "");
en = en.pad(length, "");
he = he.pad(length, "");

var segments = [];
var start = data.textDepth == data.sections.length ? data.sections[data.textDepth] : 1;
for (var i = 0; i < en.length; i++) {
for (var i = 0; i < length; i++) {
var ref = data.ref + ":" + (i+start);
segments.push({
en: en[i],
Expand Down Expand Up @@ -407,7 +407,8 @@
},
handleClick: function() {
if (this.props.openOnClick) {
this.props.showBaseText(this.props.sref);
var sectionRef = sjs.library.text(this.props.sref).sectionRef;
this.props.showBaseText(sectionRef);
}
},
nextSection: function() {
Expand Down Expand Up @@ -497,7 +498,9 @@
},
loadConnections: function() {
sjs.library.links(this.props.sref, function(links) {
this.setState({links: links});
if (this.isMounted()) {
this.setState({links: links});
}
}.bind(this));
},
componentDidMount: function() {
Expand Down Expand Up @@ -579,7 +582,6 @@
}.bind(this)).map(function(link) {
return link.sourceRef;
}).sort();
console.log(refs);
return (
<div className={classes}>
<div className="textListTop">
Expand Down Expand Up @@ -778,7 +780,7 @@
<div className={classes} onClick={this.handleClick}>
{this.props.category} | {this.props.count}
</div>
<ThreeBox content={ textFilters } />
<TwoBox content={ textFilters } />
</div>
);
}
Expand Down Expand Up @@ -845,9 +847,41 @@
</table>
);
}
})
});


var TwoBox = React.createClass({
// Wrap a list of elements into a three column table
render: function() {
var content = this.props.content;
var length = content.length;
if (length % 2) {
length += (2-length%2);
}
content.pad(length, "");
var threes = [];
for (var i=0; i<length; i+=2) {
threes.push([content[i], content[i+1]]);
}
return (
<table>
<tbody>
{
threes.map(function(row, i) {
return (
<tr key={i}>
<td className={row[0] ? "" : "empty"}>{row[0]}</td>
<td className={row[1] ? "" : "empty"}>{row[1]}</td>
</tr>
);
})
}
</tbody>
</table>
);
}
});

//var initialRef = "{{ ref }} || $.cookie("lastRef");
React.render(
<ReaderApp initialRef={humanRef("{{ ref }}")} />,
document.getElementById('s2')
Expand Down

0 comments on commit edbd6d6

Please sign in to comment.