2013-11-05 08:52:32 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/storyviews/pop.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: storyview
|
|
|
|
|
|
|
|
Animates list insertions and removals
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var PopStoryView = function(listWidget) {
|
|
|
|
this.listWidget = listWidget;
|
2014-08-30 19:44:26 +00:00
|
|
|
};
|
2013-11-05 08:52:32 +00:00
|
|
|
|
2013-11-05 09:00:31 +00:00
|
|
|
PopStoryView.prototype.navigateTo = function(historyInfo) {
|
2013-11-05 08:52:32 +00:00
|
|
|
var listElementIndex = this.listWidget.findListItem(0,historyInfo.title);
|
|
|
|
if(listElementIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var listItemWidget = this.listWidget.children[listElementIndex],
|
|
|
|
targetElement = listItemWidget.findFirstDomNode();
|
2014-09-27 09:34:59 +00:00
|
|
|
// Abandon if the list entry isn't a DOM element (it might be a text node)
|
2021-06-09 09:18:15 +00:00
|
|
|
if(!targetElement || targetElement.nodeType === Node.TEXT_NODE) {
|
2014-09-27 09:34:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-11-05 08:52:32 +00:00
|
|
|
// Scroll the node into view
|
2014-08-28 20:43:44 +00:00
|
|
|
this.listWidget.dispatchEvent({type: "tm-scroll", target: targetElement});
|
2013-11-05 08:52:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PopStoryView.prototype.insert = function(widget) {
|
|
|
|
var targetElement = widget.findFirstDomNode(),
|
|
|
|
duration = $tw.utils.getAnimationDuration();
|
2014-09-27 09:34:59 +00:00
|
|
|
// Abandon if the list entry isn't a DOM element (it might be a text node)
|
2021-06-09 09:18:15 +00:00
|
|
|
if(!targetElement || targetElement.nodeType === Node.TEXT_NODE) {
|
2014-09-27 09:34:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-11-05 08:52:32 +00:00
|
|
|
// Reset once the transition is over
|
|
|
|
setTimeout(function() {
|
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: "none"},
|
|
|
|
{transform: "none"}
|
|
|
|
]);
|
2019-06-26 10:50:52 +00:00
|
|
|
$tw.utils.setStyle(widget.document.body,[
|
|
|
|
{"overflow-x": ""}
|
|
|
|
]);
|
2013-11-05 08:52:32 +00:00
|
|
|
},duration);
|
2019-06-26 10:50:52 +00:00
|
|
|
// Prevent the page from overscrolling due to the zoom factor
|
|
|
|
$tw.utils.setStyle(widget.document.body,[
|
|
|
|
{"overflow-x": "hidden"}
|
|
|
|
]);
|
2013-11-05 08:52:32 +00:00
|
|
|
// Set up the initial position of the element
|
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: "none"},
|
|
|
|
{transform: "scale(2)"},
|
|
|
|
{opacity: "0.0"}
|
|
|
|
]);
|
|
|
|
$tw.utils.forceLayout(targetElement);
|
|
|
|
// Transition to the final position
|
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out, " +
|
|
|
|
"opacity " + duration + "ms ease-in-out"},
|
|
|
|
{transform: "scale(1)"},
|
|
|
|
{opacity: "1.0"}
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
|
|
|
|
PopStoryView.prototype.remove = function(widget) {
|
|
|
|
var targetElement = widget.findFirstDomNode(),
|
2014-09-27 09:34:59 +00:00
|
|
|
duration = $tw.utils.getAnimationDuration(),
|
|
|
|
removeElement = function() {
|
2019-08-02 07:51:16 +00:00
|
|
|
if(targetElement && targetElement.parentNode) {
|
2023-05-18 16:27:05 +00:00
|
|
|
widget.removeChildDomNodes();
|
2014-09-27 09:34:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
// Abandon if the list entry isn't a DOM element (it might be a text node)
|
2021-06-09 09:18:15 +00:00
|
|
|
if(!targetElement || targetElement.nodeType === Node.TEXT_NODE) {
|
2014-09-27 09:34:59 +00:00
|
|
|
removeElement();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-05 08:52:32 +00:00
|
|
|
// Remove the element at the end of the transition
|
2014-09-27 09:34:59 +00:00
|
|
|
setTimeout(removeElement,duration);
|
2013-11-05 08:52:32 +00:00
|
|
|
// Animate the closure
|
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: "none"},
|
|
|
|
{transform: "scale(1)"},
|
|
|
|
{opacity: "1.0"}
|
|
|
|
]);
|
|
|
|
$tw.utils.forceLayout(targetElement);
|
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out, " +
|
|
|
|
"opacity " + duration + "ms ease-in-out"},
|
|
|
|
{transform: "scale(0.1)"},
|
|
|
|
{opacity: "0.0"}
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.pop = PopStoryView;
|
|
|
|
|
|
|
|
})();
|