2012-10-23 16:13:47 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/macros/list/listviews/classic.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: listview
|
|
|
|
|
|
|
|
Views the list as a linear sequence
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function ClassicListView(listMacro) {
|
|
|
|
this.listMacro = listMacro;
|
2012-10-25 21:20:27 +00:00
|
|
|
}
|
2012-10-23 16:13:47 +00:00
|
|
|
|
2012-10-26 21:12:40 +00:00
|
|
|
ClassicListView.prototype.navigateTo = function(historyInfo) {
|
|
|
|
var listElementIndex = this.listMacro.findListElementByTitle(0,historyInfo.title),
|
2012-10-26 16:19:34 +00:00
|
|
|
listElementNode = this.listMacro.listFrame.children[listElementIndex],
|
|
|
|
targetElement = listElementNode.domNode;
|
2012-10-26 21:12:40 +00:00
|
|
|
// Remove any transform on the target element
|
2012-10-26 16:19:34 +00:00
|
|
|
$tw.utils.setStyle(targetElement,[
|
2012-10-26 21:12:40 +00:00
|
|
|
{transition: "none"},
|
|
|
|
{transformOrigin: "0% 0%"},
|
|
|
|
{height: "auto"}
|
2012-10-26 16:19:34 +00:00
|
|
|
]);
|
2012-10-28 09:51:19 +00:00
|
|
|
// Get the current height of the element
|
2012-10-28 09:30:45 +00:00
|
|
|
var currHeight = targetElement.offsetHeight;
|
2012-10-26 21:12:40 +00:00
|
|
|
// Compute the start and end positions of the target element
|
|
|
|
var srcRect = historyInfo.fromPageRect;
|
|
|
|
if(!srcRect) {
|
|
|
|
var scrollPos = $tw.utils.getScrollPosition();
|
|
|
|
srcRect = {
|
|
|
|
left: scrollPos.x,
|
|
|
|
top: scrollPos.y,
|
2012-10-28 14:13:38 +00:00
|
|
|
right: scrollPos.x + window.innerWidth,
|
|
|
|
bottom: scrollPos.y + window.innerHeight,
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight
|
2012-10-26 21:12:40 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
var dstRect = $tw.utils.getBoundingPageRect(targetElement);
|
|
|
|
// Compute the transformations
|
|
|
|
var scale = srcRect.width / dstRect.width;
|
2012-10-28 09:30:45 +00:00
|
|
|
// 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);
|
2012-10-26 21:12:40 +00:00
|
|
|
// Position the target element over the source rectangle
|
2012-10-26 16:19:34 +00:00
|
|
|
$tw.utils.setStyle(targetElement,[
|
2012-10-28 09:30:45 +00:00
|
|
|
{transform: "translateX(" + (srcRect.left-dstRect.left) + "px) translateY(" + (srcRect.top-dstRect.top) + "px) scale(" + scale + ")"},
|
|
|
|
{height: "0px"}
|
2012-10-26 16:19:34 +00:00
|
|
|
]);
|
|
|
|
$tw.utils.forceLayout(targetElement);
|
2012-10-26 21:12:40 +00:00
|
|
|
// Transition the target element to its final resting place
|
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out, " +
|
2012-10-28 09:30:45 +00:00
|
|
|
"opacity " + $tw.config.preferences.animationDurationMs + " ease-out, " +
|
|
|
|
"height " + $tw.config.preferences.animationDurationMs + " ease-in-out"},
|
|
|
|
{transform: "none"},
|
|
|
|
{height: currHeight + "px"}
|
2012-10-26 21:12:40 +00:00
|
|
|
]);
|
2012-10-26 16:19:34 +00:00
|
|
|
// Scroll the target element into view
|
2012-10-28 09:51:59 +00:00
|
|
|
$tw.scroller.scrollIntoView(dstRect);
|
2012-10-26 16:19:34 +00:00
|
|
|
};
|
|
|
|
|
2012-10-23 17:19:20 +00:00
|
|
|
ClassicListView.prototype.insert = function(index) {
|
|
|
|
var listElementNode = this.listMacro.listFrame.children[index],
|
|
|
|
targetElement = listElementNode.domNode;
|
|
|
|
// Get the current height of the tiddler
|
|
|
|
var currHeight = targetElement.offsetHeight;
|
2012-10-26 21:12:40 +00:00
|
|
|
// 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
|
2012-10-25 21:20:27 +00:00
|
|
|
$tw.utils.setStyle(targetElement,[
|
2012-10-26 21:12:40 +00:00
|
|
|
{transition: "none"},
|
2012-10-25 21:20:27 +00:00
|
|
|
{transformOrigin: "0% 0%"},
|
|
|
|
{transform: "translateX(" + window.innerWidth + "px)"},
|
|
|
|
{opacity: "0.0"},
|
|
|
|
{height: "0px"}
|
|
|
|
]);
|
2012-10-23 17:19:20 +00:00
|
|
|
$tw.utils.forceLayout(targetElement);
|
2012-10-26 21:12:40 +00:00
|
|
|
// Transition to the final position
|
2012-10-25 21:20:27 +00:00
|
|
|
$tw.utils.setStyle(targetElement,[
|
|
|
|
{transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out, " +
|
|
|
|
"opacity " + $tw.config.preferences.animationDurationMs + " ease-out, " +
|
|
|
|
"height " + $tw.config.preferences.animationDurationMs + " ease-in-out"},
|
|
|
|
{transform: "translateX(0px)"},
|
|
|
|
{opacity: "1.0"},
|
|
|
|
{height: currHeight + "px"}
|
|
|
|
]);
|
2012-10-23 17:19:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ClassicListView.prototype.remove = function(index) {
|
|
|
|
var listElementNode = this.listMacro.listFrame.children[index],
|
|
|
|
targetElement = listElementNode.domNode;
|
|
|
|
// Get the current height of the tiddler
|
|
|
|
var currHeight = targetElement.offsetHeight;
|
|
|
|
// Put a wrapper around the dom node we're closing
|
|
|
|
var wrapperElement = document.createElement("div");
|
|
|
|
targetElement.parentNode.insertBefore(wrapperElement,targetElement);
|
|
|
|
wrapperElement.appendChild(targetElement);
|
|
|
|
// Attach an event handler for the end of the transition
|
2012-10-26 13:01:11 +00:00
|
|
|
wrapperElement.addEventListener($tw.utils.convertEventName("transitionEnd"),function(event) {
|
2012-10-23 17:19:20 +00:00
|
|
|
if(wrapperElement.parentNode) {
|
|
|
|
wrapperElement.parentNode.removeChild(wrapperElement);
|
|
|
|
}
|
|
|
|
},false);
|
|
|
|
// Animate the closure
|
2012-10-25 21:20:27 +00:00
|
|
|
$tw.utils.setStyle(wrapperElement,[
|
|
|
|
{transition: $tw.utils.roundTripPropertyName("transform") + " " + $tw.config.preferences.animationDurationMs + " ease-in-out, " +
|
|
|
|
"opacity " + $tw.config.preferences.animationDurationMs + " ease-out, " +
|
|
|
|
"height " + $tw.config.preferences.animationDurationMs + " ease-in-out"},
|
|
|
|
{transformOrigin: "0% 0%"},
|
|
|
|
{transform: "translateX(0px)"},
|
|
|
|
{opacity: "1.0"},
|
|
|
|
{height: currHeight + "px"}
|
|
|
|
]);
|
2012-10-23 17:19:20 +00:00
|
|
|
$tw.utils.forceLayout(wrapperElement);
|
2012-10-25 21:20:27 +00:00
|
|
|
$tw.utils.setStyle(wrapperElement,[
|
|
|
|
{transform: "translateX(-" + window.innerWidth + "px)"},
|
|
|
|
{opacity: "0.0"},
|
|
|
|
{height: "0px"}
|
|
|
|
]);
|
2012-10-23 17:19:20 +00:00
|
|
|
// Returning true causes the DOM node not to be deleted
|
|
|
|
return true;
|
2012-10-23 16:13:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports["classic"] = ClassicListView;
|
|
|
|
|
|
|
|
})();
|