1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-12 02:10:27 +00:00

Further refinements to the list mechanism

Much better navigation animation for classic view
This commit is contained in:
Jeremy Ruston 2012-10-26 22:12:40 +01:00
parent 865e26bbce
commit 324a87a8a2
6 changed files with 67 additions and 21 deletions

View File

@ -35,7 +35,8 @@ exports.handleEvent = function (event) {
var navEvent = document.createEvent("Event"); var navEvent = document.createEvent("Event");
navEvent.initEvent("tw-navigate",true,true); navEvent.initEvent("tw-navigate",true,true);
navEvent.navigateTo = this.linkInfo.to; navEvent.navigateTo = this.linkInfo.to;
navEvent.navigateFrom = this; navEvent.navigateFromNode = this;
navEvent.navigateFromPageRect = $tw.utils.getBoundingPageRect(this.child.domNode);
event.target.dispatchEvent(navEvent); event.target.dispatchEvent(navEvent);
event.preventDefault(); event.preventDefault();
return false; return false;

View File

@ -294,7 +294,7 @@ exports.handleHistoryChanges = function() {
// Navigate forwards to each of the new tiddlers // Navigate forwards to each of the new tiddlers
while(entry < newHistory.length) { while(entry < newHistory.length) {
if(this.listview && this.listview.navigateTo) { if(this.listview && this.listview.navigateTo) {
this.listview.navigateTo(newHistory[entry].title); this.listview.navigateTo(newHistory[entry]);
} }
entry++; entry++;
} }

View File

@ -16,19 +16,46 @@ function ClassicListView(listMacro) {
this.listMacro = listMacro; this.listMacro = listMacro;
} }
ClassicListView.prototype.navigateTo = function(title) { ClassicListView.prototype.navigateTo = function(historyInfo) {
var listElementIndex = this.listMacro.findListElementByTitle(0,title), var listElementIndex = this.listMacro.findListElementByTitle(0,historyInfo.title),
listElementNode = this.listMacro.listFrame.children[listElementIndex], listElementNode = this.listMacro.listFrame.children[listElementIndex],
targetElement = listElementNode.domNode; targetElement = listElementNode.domNode;
// Replace any previous transition on the target element // Remove any transform on the target element
$tw.utils.setStyle(targetElement,[ $tw.utils.setStyle(targetElement,[
{transition: ""} {transition: "none"},
{transformOrigin: "0% 0%"},
{transform: "none"},
{height: "auto"}
]);
// Compute the start and end positions of the target element
var srcRect = historyInfo.fromPageRect;
if(!srcRect) {
var scrollPos = $tw.utils.getScrollPosition();
srcRect.width = window.innerWidth;
srcRect.height = window.innerHeight;
srcRect = {
left: scrollPos.x,
top: scrollPos.y,
right: scrollPos.x + srcRect.width,
bottom: scrollPos.y + srcRect.height
};
};
$tw.utils.forceLayout(targetElement);
var dstRect = $tw.utils.getBoundingPageRect(targetElement);
// Compute the transformations
var scale = srcRect.width / dstRect.width;
// Position the target element over the source rectangle
$tw.utils.setStyle(targetElement,[
{transition: "none"},
{transform: "translateX(" + (srcRect.left-dstRect.left) + "px) translateY(" + (srcRect.top-dstRect.top) + "px) scale(" + scale + ")"}
]); ]);
$tw.utils.forceLayout(targetElement); $tw.utils.forceLayout(targetElement);
// Transition the target element to its final resting place
$tw.utils.setStyle(targetElement,[ $tw.utils.setStyle(targetElement,[
{transform: ""}, {transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out, " +
"opacity " + $tw.config.preferences.animationDurationMs + " ease-out"},
{transform: "none"}
]); ]);
$tw.utils.forceLayout(targetElement);
// Scroll the target element into view // Scroll the target element into view
$tw.scroller.scrollIntoView(targetElement); $tw.scroller.scrollIntoView(targetElement);
}; };
@ -38,21 +65,23 @@ ClassicListView.prototype.insert = function(index) {
targetElement = listElementNode.domNode; targetElement = listElementNode.domNode;
// Get the current height of the tiddler // Get the current height of the tiddler
var currHeight = targetElement.offsetHeight; var currHeight = targetElement.offsetHeight;
// Animate the closure // Reset the height once the transition is over
targetElement.addEventListener($tw.utils.convertEventName("transitionEnd"),function(event) {
$tw.utils.setStyle(targetElement,[
{transition: "none"},
{height: "auto"}
]);
},false);
// Set up the initial position of the element
$tw.utils.setStyle(targetElement,[ $tw.utils.setStyle(targetElement,[
{transition: ""}, {transition: "none"},
{transformOrigin: "0% 0%"}, {transformOrigin: "0% 0%"},
{transform: "translateX(" + window.innerWidth + "px)"}, {transform: "translateX(" + window.innerWidth + "px)"},
{opacity: "0.0"}, {opacity: "0.0"},
{height: "0px"} {height: "0px"}
]); ]);
$tw.utils.forceLayout(targetElement); $tw.utils.forceLayout(targetElement);
targetElement.addEventListener($tw.utils.convertEventName("transitionEnd"),function(event) { // Transition to the final position
$tw.utils.setStyle(targetElement,[
{transition: ""},
{height: "auto"}
]);
},false);
$tw.utils.setStyle(targetElement,[ $tw.utils.setStyle(targetElement,[
{transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out, " + {transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out, " +
"opacity " + $tw.config.preferences.animationDurationMs + " ease-out, " + "opacity " + $tw.config.preferences.animationDurationMs + " ease-out, " +

View File

@ -70,7 +70,7 @@ exports.eventMap["tw-navigate"] = function(event) {
} }
// Add a new record to the top of the history stack // Add a new record to the top of the history stack
this.history = this.wiki.getTiddlerData(this.historyTitle,[]); this.history = this.wiki.getTiddlerData(this.historyTitle,[]);
this.history.push({title: event.navigateTo}); this.history.push({title: event.navigateTo, fromPageRect: event.navigateFromPageRect});
this.wiki.setTiddlerData(this.historyTitle,this.history); this.wiki.setTiddlerData(this.historyTitle,this.history);
event.stopPropagation(); event.stopPropagation();
return false; return false;

View File

@ -92,20 +92,20 @@ var eventNameMappings = {
"transitionEnd": { "transitionEnd": {
correspondingCssProperty: "transition", correspondingCssProperty: "transition",
mappings: { mappings: {
transition: "transitionEnd", transition: "transitionend",
OTransition: "oTransitionEnd", OTransition: "oTransitionEnd",
MSTransition: "msTransitionEnd", MSTransition: "msTransitionEnd",
MozTransition: "transitionEnd", MozTransition: "transitionend",
webkitTransition: "webkitTransitionEnd" webkitTransition: "webkitTransitionEnd"
} }
}, },
"animationEnd": { "animationEnd": {
correspondingCssProperty: "animation", correspondingCssProperty: "animation",
mappings: { mappings: {
animation: "animationEnd", animation: "animationend",
OAnimation: "oAnimationEnd", OAnimation: "oAnimationEnd",
MSAnimation: "msAnimationEnd", MSAnimation: "msAnimationEnd",
MozAnimation: "animationEnd", MozAnimation: "animationend",
webkitAnimation: "webkitAnimationEnd" webkitAnimation: "webkitAnimationEnd"
} }
} }

View File

@ -91,6 +91,22 @@ exports.getScrollPosition = function() {
} }
}; };
/*
Gets the bounding rectangle of an element in absolute page coordinates
*/
exports.getBoundingPageRect = function(element) {
var scrollPos = $tw.utils.getScrollPosition(),
clientRect = element.getBoundingClientRect();
return {
left: clientRect.left + scrollPos.x,
width: clientRect.width,
right: clientRect.right + scrollPos.x,
top: clientRect.top + scrollPos.y,
height: clientRect.height,
bottom: clientRect.bottom + scrollPos.y
};
};
/* /*
Saves a named password in the browser Saves a named password in the browser
*/ */