forked from openlp/openlp
Detect repeat verses
This commit is contained in:
parent
e940279b34
commit
ef5c4bc7d4
@ -51,24 +51,50 @@ window.OpenLP = {
|
|||||||
div.html("");
|
div.html("");
|
||||||
var tag = "";
|
var tag = "";
|
||||||
var tags = 0;
|
var tags = 0;
|
||||||
for (idx in data.results.slides) {
|
var lastChange = 0;
|
||||||
idx = parseInt(idx, 10);
|
$.each(data.results.slides, function(idx, slide) {
|
||||||
var prevtag = tag;
|
var prevtag = tag;
|
||||||
tag = data.results.slides[idx]["tag"];
|
tag = slide["tag"];
|
||||||
if (tag != prevtag) {
|
if (tag != prevtag) {
|
||||||
|
// If the tag has changed, add new one to the list
|
||||||
|
lastChange = idx;
|
||||||
tags = tags + 1;
|
tags = tags + 1;
|
||||||
div.append(" <span>");
|
div.append(" <span>");
|
||||||
$("#verseorder span").last().attr("id", "tag" + tags).text(tag);
|
$("#verseorder span").last().attr("id", "tag" + tags).text(tag);
|
||||||
}
|
}
|
||||||
OpenLP.currentTags[idx] = tags;
|
else {
|
||||||
if (data.results.slides[idx]["selected"])
|
if ((slide["text"] == data.results.slides[lastChange]["text"]) &&
|
||||||
OpenLP.currentSlide = idx;
|
(data.results.slides.length > idx + (idx - lastChange))) {
|
||||||
|
// If the tag hasn't changed, check to see if the same verse
|
||||||
|
// has been repeated consecutively. Note the verse may have been
|
||||||
|
// split over several slides, so search through. If so, repeat the tag.
|
||||||
|
var match = true;
|
||||||
|
for (var idx2 = 0; idx2 < idx - lastChange; idx2++) {
|
||||||
|
if(data.results.slides[lastChange + idx2]["text"] != data.results.slides[idx + idx2]["text"]) {
|
||||||
|
match = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (match) {
|
||||||
|
lastChange = idx;
|
||||||
|
tags = tags + 1;
|
||||||
|
div.append(" <span>");
|
||||||
|
$("#verseorder span").last().attr("id", "tag" + tags).text(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OpenLP.currentTags[idx] = tags;
|
||||||
|
if (slide["selected"])
|
||||||
|
OpenLP.currentSlide = idx;
|
||||||
|
})
|
||||||
OpenLP.loadService();
|
OpenLP.loadService();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
updateSlide: function() {
|
updateSlide: function() {
|
||||||
|
// Show the current slide on top. Any trailing slides for the same verse
|
||||||
|
// are shown too underneath in grey.
|
||||||
|
// Then leave a blank line between following verses
|
||||||
$("#verseorder span").removeClass("currenttag");
|
$("#verseorder span").removeClass("currenttag");
|
||||||
$("#tag" + OpenLP.currentTags[OpenLP.currentSlide]).addClass("currenttag");
|
$("#tag" + OpenLP.currentTags[OpenLP.currentSlide]).addClass("currenttag");
|
||||||
var slide = OpenLP.currentSlides[OpenLP.currentSlide];
|
var slide = OpenLP.currentSlides[OpenLP.currentSlide];
|
||||||
@ -78,12 +104,10 @@ window.OpenLP = {
|
|||||||
text = "";
|
text = "";
|
||||||
if (OpenLP.currentSlide < OpenLP.currentSlides.length - 1) {
|
if (OpenLP.currentSlide < OpenLP.currentSlides.length - 1) {
|
||||||
for (var idx = OpenLP.currentSlide + 1; idx < OpenLP.currentSlides.length; idx++) {
|
for (var idx = OpenLP.currentSlide + 1; idx < OpenLP.currentSlides.length; idx++) {
|
||||||
var prevslide = slide;
|
if (OpenLP.currentTags[idx] != OpenLP.currentTags[idx - 1])
|
||||||
slide = OpenLP.currentSlides[idx];
|
|
||||||
if (slide["tag"] != prevslide["tag"])
|
|
||||||
text = text + '<p class="nextslide">';
|
text = text + '<p class="nextslide">';
|
||||||
text = text + slide["text"];
|
text = text + OpenLP.currentSlides[idx]["text"];
|
||||||
if (slide["tag"] != prevslide["tag"])
|
if (OpenLP.currentTags[idx] != OpenLP.currentTags[idx - 1])
|
||||||
text = text + '</p>';
|
text = text + '</p>';
|
||||||
else
|
else
|
||||||
text = text + '<br />';
|
text = text + '<br />';
|
||||||
@ -91,9 +115,10 @@ window.OpenLP = {
|
|||||||
text = text.replace(/\n/g, '<br />');
|
text = text.replace(/\n/g, '<br />');
|
||||||
$("#nextslide").html(text);
|
$("#nextslide").html(text);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
text = '<p class="nextslide">Next: ' + OpenLP.nextSong + '</p>';
|
text = '<p class="nextslide">Next: ' + OpenLP.nextSong + '</p>';
|
||||||
$("#nextslide").html(text);
|
$("#nextslide").html(text);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
updateClock: function() {
|
updateClock: function() {
|
||||||
var div = $("#clock");
|
var div = $("#clock");
|
||||||
|
Loading…
Reference in New Issue
Block a user