forked from openlp/openlp
Fixed all tests and changed entrance transition to class based toggling
This commit is contained in:
parent
c25f4d8197
commit
0e1989f06f
@ -27,6 +27,16 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bg-default.show {
|
||||||
|
height: auto;
|
||||||
|
min-height: 25%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bg-default.hide {
|
||||||
|
height: 0;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.bg-default.middle {
|
.bg-default.middle {
|
||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="reveal">
|
<div class="reveal">
|
||||||
<div id="global-background" class="slide-background present" data-loaded="true"></div>
|
<div id="global-background" class="slide-background present" data-loaded="true"></div>
|
||||||
<div id="alert-background" class="bg-default"><p class="" id="alert">Testing alerts</p></div>
|
<div id="alert-background" class="bg-default hide"><p class="" id="alert">Testing alerts</p></div>
|
||||||
<div class="slides"></div>
|
<div class="slides"></div>
|
||||||
<div class="footer"></div>
|
<div class="footer"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -413,19 +413,28 @@ var Display = {
|
|||||||
* "timeout": 10, "repeat": 2, "scroll": true}'
|
* "timeout": 10, "repeat": 2, "scroll": true}'
|
||||||
*/
|
*/
|
||||||
alert: function (text, alert_settings) {
|
alert: function (text, alert_settings) {
|
||||||
|
var alertBackground = $('#alert-background')[0];
|
||||||
|
var alertText = $('#alert')[0];
|
||||||
if (text == "") {
|
if (text == "") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this._alertState === AlertState.Displaying || this._alertState === AlertState.DisplayingFromQueue) {
|
if (this._alertState === AlertState.Displaying || this._alertState === AlertState.DisplayingFromQueue) {
|
||||||
addAlertToQueue(text, alert_settings);
|
Display.addAlertToQueue(text, alert_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var settings = JSON.parse(alert_settings);
|
var settings = JSON.parse(alert_settings);
|
||||||
this._alertSettings = settings;
|
this._alertSettings = settings;
|
||||||
Display.setAlertText(text);
|
Display.setAlertText(text);
|
||||||
|
|
||||||
Display.initAlertEventListeners();
|
alertBackground.addEventListener('transitionend', function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
Display.alertTransitionEndEvent();
|
||||||
|
});
|
||||||
|
alertText.addEventListener('animationend', function(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
Display.alertAnimationEndEvent();
|
||||||
|
});
|
||||||
|
|
||||||
if (settings.scroll === true) {
|
if (settings.scroll === true) {
|
||||||
Display.setAlertKeyframes($('#alert'[0].scrollWidth));
|
Display.setAlertKeyframes($('#alert'[0].scrollWidth));
|
||||||
@ -437,16 +446,6 @@ var Display = {
|
|||||||
|
|
||||||
Display.showAlertBackground(settings);
|
Display.showAlertBackground(settings);
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* Initialize alert event listeners
|
|
||||||
*/
|
|
||||||
initAlertEventListeners: function () {
|
|
||||||
var alertBackground = $("#alert-background")[0];
|
|
||||||
var alertText = $("#alert")[0];
|
|
||||||
|
|
||||||
alertBackground.addEventListener('transitionend', Display.alertTransitionEndEvent, false);
|
|
||||||
alertText.addEventListener('animationend', Display.alertAnimationEndEvent, false);
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Add an alert to the alert queue
|
* Add an alert to the alert queue
|
||||||
* @param {string} text - The alert text to be displayed
|
* @param {string} text - The alert text to be displayed
|
||||||
@ -482,28 +481,20 @@ var Display = {
|
|||||||
/**
|
/**
|
||||||
* The alertTransitionEndEvent called after a transition has ended
|
* The alertTransitionEndEvent called after a transition has ended
|
||||||
*/
|
*/
|
||||||
alertTransitionEndEvent: function (e) {
|
alertTransitionEndEvent: function () {
|
||||||
e.stopPropagation();
|
|
||||||
if (Display._transitionState === TransitionState.EntranceTransition) {
|
if (Display._transitionState === TransitionState.EntranceTransition) {
|
||||||
Display._transitionState = TransitionState.NoTransition;
|
Display._transitionState = TransitionState.NoTransition;
|
||||||
Display.showAlertText(Display._alertSettings);
|
Display.showAlertText(Display._alertSettings);
|
||||||
console.log("Show alert has been called");
|
|
||||||
}
|
}
|
||||||
else if (Display._transitionState === TransitionState.ExitTransition) {
|
else if (Display._transitionState === TransitionState.ExitTransition) {
|
||||||
Display._transitionState = TransitionState.NoTransition;
|
Display._transitionState = TransitionState.NoTransition;
|
||||||
Display.displayNextAlert();
|
Display.displayNextAlert();
|
||||||
}
|
}
|
||||||
else if (Display._transitionState === "animatingText") {
|
|
||||||
if (e.propertyName === "transform") {
|
|
||||||
console.log("The text transform has ended");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* The alertAnimationEndEvent called after a animation has ended
|
* The alertAnimationEndEvent called after a animation has ended
|
||||||
*/
|
*/
|
||||||
alertAnimationEndEvent: function (e) {
|
alertAnimationEndEvent: function () {
|
||||||
e.stopPropagation();
|
|
||||||
Display.hideAlertText();
|
Display.hideAlertText();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -519,17 +510,16 @@ var Display = {
|
|||||||
alertBackground.style.backgroundColor = settings.background_color;
|
alertBackground.style.backgroundColor = settings.background_color;
|
||||||
|
|
||||||
if (Display._alertState === AlertState.DisplayingFromQueue) {
|
if (Display._alertState === AlertState.DisplayingFromQueue) {
|
||||||
transitionSetting = "height 1s linear 2s";
|
transitionSetting = "min-height 1s linear 2s";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
transitionSetting = "height 1s linear";
|
transitionSetting = "min-height 1s linear";
|
||||||
}
|
}
|
||||||
// Wait for styles to be set first before starting transition
|
// Wait for styles to be set first before starting transition
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
alertBackground.style.height = "auto";
|
|
||||||
alertBackground.style.minHeight = "25%";
|
|
||||||
alertBackground.style.transition = transitionSetting;
|
alertBackground.style.transition = transitionSetting;
|
||||||
alertBackground.style.visibility = "visible";
|
alertBackground.classList.add("show");
|
||||||
|
alertBackground.classList.remove("hide");
|
||||||
}, 50);
|
}, 50);
|
||||||
this._transitionState = TransitionState.EntranceTransition;
|
this._transitionState = TransitionState.EntranceTransition;
|
||||||
},
|
},
|
||||||
@ -558,10 +548,9 @@ var Display = {
|
|||||||
*/
|
*/
|
||||||
hideAlertBackground: function () {
|
hideAlertBackground: function () {
|
||||||
var alertBackground = $("#alert-background")[0];
|
var alertBackground = $("#alert-background")[0];
|
||||||
alertBackground.style.height = "0%";
|
alertBackground.style.transition = "min-height 1s linear";
|
||||||
alertBackground.style.minHeight = "0%";
|
alertBackground.classList.remove("show");
|
||||||
alertBackground.style.transition = "height 1s linear";
|
alertBackground.classList.add("hide");
|
||||||
alertBackground.className = "bg-default";
|
|
||||||
this._transitionState = TransitionState.ExitTransition;
|
this._transitionState = TransitionState.ExitTransition;
|
||||||
this._alertState = AlertState.NotDisplaying;
|
this._alertState = AlertState.NotDisplaying;
|
||||||
},
|
},
|
||||||
|
@ -176,18 +176,15 @@ describe("Display.alert", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the correct alert text", function () {
|
it("should set the correct alert text", function () {
|
||||||
spyOn("Display", "addAlertToQueue");
|
spyOn(Display, "setAlertKeyframes");
|
||||||
spyOn("Display", "initAlertEventListeners");
|
|
||||||
spyOn("Display", "setAlertKeyframes");
|
|
||||||
spyOn("Display", "showAlertBackground");
|
|
||||||
Display.alert("OPEN-LP-3.0 Alert Test", settings);
|
Display.alert("OPEN-LP-3.0 Alert Test", settings);
|
||||||
|
|
||||||
expect(Display.setAlertText).toHaveBeenCalled();
|
expect(alertText.innerHTML).toEqual("OPEN-LP-3.0 Alert Test");
|
||||||
expect(alert.innerHTML).toEqual("OPEN-LP-3.0 Alert Test");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call the addAlertToQueue method if an alert is displaying", function () {
|
it("should call the addAlertToQueue method if an alert is displaying", function () {
|
||||||
spyOn("Display", "addAlertToQueue");
|
spyOn(Display, "addAlertToQueue");
|
||||||
|
spyOn(Display, "setAlertKeyframes");
|
||||||
Display._alerts = [];
|
Display._alerts = [];
|
||||||
Display._alertState = AlertState.Displaying;
|
Display._alertState = AlertState.Displaying;
|
||||||
var text = "Testing alert queue";
|
var text = "Testing alert queue";
|
||||||
@ -198,50 +195,13 @@ describe("Display.alert", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should set the alert settings correctly", function() {
|
it("should set the alert settings correctly", function() {
|
||||||
spyOn("Display", "setAlertKeyframes");
|
spyOn(Display, "setAlertKeyframes");
|
||||||
Display.alert("Testing settings", settings);
|
Display.alert("Testing settings", settings);
|
||||||
|
|
||||||
expect(Display._alertSettings).toEqual(JSON.parse(settings));
|
expect(Display._alertSettings).toEqual(JSON.parse(settings));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Display.initAlertEventListeners", function() {
|
|
||||||
var alertBackground, styles, alertText;
|
|
||||||
beforeEach(function() {
|
|
||||||
document.body.innerHTML = "";
|
|
||||||
styles = document.createElement("style");
|
|
||||||
styles.innerHTML = "@keyframes test { from {background-color: red;} \
|
|
||||||
to {background-color: yellow;}";
|
|
||||||
document.head.appendChild(styles);
|
|
||||||
alertBackground = document.createElement("div");
|
|
||||||
alertBackground.setAttribute("id", "alert-background");
|
|
||||||
document.body.appendChild(alertBackground);
|
|
||||||
alertText = document.createElement("p");
|
|
||||||
alertText.setAttribute("id","alert");
|
|
||||||
alertBackground.appendChild(alertText);
|
|
||||||
alertBackground.style.opacity = 0;
|
|
||||||
alertBackground.style.transition = "opacity 0.001s linear";
|
|
||||||
Display.initAlertEventListeners();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should set the transition end event listener correctly", function() {
|
|
||||||
spyOn("Display", "alertTransitionEndEvent");
|
|
||||||
|
|
||||||
alertBackground.style.opacity = 1;
|
|
||||||
|
|
||||||
expect(Display.alertTransitionEndEvent).toHaveBeenCalled();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should set the animation end event listener correctly", function() {
|
|
||||||
spyOn("Display", "alertAnimationEndEvent");
|
|
||||||
|
|
||||||
alertText.style.animation = "test 0.01s linear";
|
|
||||||
|
|
||||||
expect(Display.alertAnimationEndEvent).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Display.showAlertBackground", function () {
|
describe("Display.showAlertBackground", function () {
|
||||||
|
|
||||||
var alertBackground, css, settings, style;
|
var alertBackground, css, settings, style;
|
||||||
@ -269,7 +229,7 @@ describe("Display.showAlertBackground", function () {
|
|||||||
it("should set the correct transition state", function () {
|
it("should set the correct transition state", function () {
|
||||||
Display.showAlertBackground(settings);
|
Display.showAlertBackground(settings);
|
||||||
expect(Display._transitionState).toEqual(TransitionState.EntranceTransition);
|
expect(Display._transitionState).toEqual(TransitionState.EntranceTransition);
|
||||||
})
|
});
|
||||||
|
|
||||||
it("should apply the styles correctly when showAlertBackground is called", function (done) {
|
it("should apply the styles correctly when showAlertBackground is called", function (done) {
|
||||||
Display.showAlertBackground(settings);
|
Display.showAlertBackground(settings);
|
||||||
@ -277,10 +237,8 @@ describe("Display.showAlertBackground", function () {
|
|||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
expect(alertBackground.style.backgroundColor).toEqual(settings.background_color);
|
expect(alertBackground.style.backgroundColor).toEqual(settings.background_color);
|
||||||
expect(alertBackground.style.height).toEqual("auto");
|
expect(alertBackground.classList.contains("show")).toBe(true);
|
||||||
expect(alertBackground.style.minHeight).toEqual("25%");
|
expect(alertBackground.style.transition).toEqual("min-height 1s linear");
|
||||||
expect(alertBackground.style.transition).toEqual("height 1s linear");
|
|
||||||
expect(alertBackground.style.visibility).toEqual("visible");
|
|
||||||
done();
|
done();
|
||||||
}, 50);
|
}, 50);
|
||||||
});
|
});
|
||||||
@ -301,10 +259,8 @@ describe("Display.hideAlertBackground", function () {
|
|||||||
|
|
||||||
expect(Display._transitionState).toEqual(TransitionState.ExitTransition);
|
expect(Display._transitionState).toEqual(TransitionState.ExitTransition);
|
||||||
expect(Display._alertState).toEqual(AlertState.NotDisplaying);
|
expect(Display._alertState).toEqual(AlertState.NotDisplaying);
|
||||||
expect(alertBackground.style.transition).toEqual("height 1s linear");
|
expect(alertBackground.style.transition).toEqual("min-height 1s linear");
|
||||||
expect(alertBackground.style.height).toEqual("0%");
|
expect(alertBackground.className).toEqual("hide");
|
||||||
expect(alertBackground.style.minHeight).toEqual("0%");
|
|
||||||
expect(alertBackground.className).toEqual("bg-default");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -488,20 +444,18 @@ describe("Display.alertTransitionEndEvent", function() {
|
|||||||
it("should set the correct state and call showAlertText after the alert entrance transition", function() {
|
it("should set the correct state and call showAlertText after the alert entrance transition", function() {
|
||||||
var fake_settings = {test: "fake_settings"};
|
var fake_settings = {test: "fake_settings"};
|
||||||
Display._alertSettings = fake_settings;
|
Display._alertSettings = fake_settings;
|
||||||
spyOn("Display", "showAlertText");
|
spyOn(Display, "showAlertText");
|
||||||
Display._transitionState = TransitionState.EntranceTransition;
|
Display._transitionState = TransitionState.EntranceTransition;
|
||||||
var event = document.createEvent("animationend");
|
Display.alertTransitionEndEvent();
|
||||||
Display.alertTransitionEnd(event);
|
|
||||||
|
|
||||||
expect(Display._transitionState).toEqual(TransitionState.NoTransition);
|
expect(Display._transitionState).toEqual(TransitionState.NoTransition);
|
||||||
expect(Display.alertTransitionEndEvent).toHaveBeenCalledWith(fake_settings);
|
expect(Display.showAlertText).toHaveBeenCalledWith(fake_settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set the correct state, class and call displayNextAlert after the alert exit transition", function() {
|
it("should set the correct state, class and call displayNextAlert after the alert exit transition", function() {
|
||||||
spyOn("Display", "displayNextAlert");
|
spyOn(Display, "displayNextAlert");
|
||||||
Display._transitionState = TransitionState.ExitTransition;
|
Display._transitionState = TransitionState.ExitTransition;
|
||||||
var event = document.createEvent("animationend");
|
Display.alertTransitionEndEvent();
|
||||||
Display.alertTransitionEnd(event);
|
|
||||||
|
|
||||||
expect(Display._transitionState).toEqual(TransitionState.NoTransition);
|
expect(Display._transitionState).toEqual(TransitionState.NoTransition);
|
||||||
expect(Display.displayNextAlert).toHaveBeenCalled();
|
expect(Display.displayNextAlert).toHaveBeenCalled();
|
||||||
@ -510,7 +464,9 @@ describe("Display.alertTransitionEndEvent", function() {
|
|||||||
|
|
||||||
describe("Display.alertAnimationEndEvent", function () {
|
describe("Display.alertAnimationEndEvent", function () {
|
||||||
it("should call the hideAlertText method", function() {
|
it("should call the hideAlertText method", function() {
|
||||||
spyOn("Display","hideAlertText");
|
spyOn(Display, "hideAlertText");
|
||||||
|
|
||||||
|
Display.alertAnimationEndEvent();
|
||||||
|
|
||||||
expect(Display.hideAlertText).toHaveBeenCalled();
|
expect(Display.hideAlertText).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user