Skip to content

Commit

Permalink
Improve storyview error detection
Browse files Browse the repository at this point in the history
Fixes #912
  • Loading branch information
Jermolene committed Sep 27, 2014
1 parent 9dff0c4 commit 115245a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
22 changes: 18 additions & 4 deletions core/modules/storyviews/classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ ClassicStoryView.prototype.navigateTo = function(historyInfo) {
}
var listItemWidget = this.listWidget.children[listElementIndex],
targetElement = listItemWidget.findFirstDomNode();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
return;
}
// Scroll the node into view
this.listWidget.dispatchEvent({type: "tm-scroll", target: targetElement});
};

ClassicStoryView.prototype.insert = function(widget) {
var targetElement = widget.findFirstDomNode(),
duration = $tw.utils.getAnimationDuration();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
return;
}
// Get the current height of the tiddler
var computedStyle = window.getComputedStyle(targetElement),
currMarginBottom = parseInt(computedStyle.marginBottom,10),
Expand Down Expand Up @@ -62,17 +70,23 @@ ClassicStoryView.prototype.insert = function(widget) {

ClassicStoryView.prototype.remove = function(widget) {
var targetElement = widget.findFirstDomNode(),
duration = $tw.utils.getAnimationDuration();
duration = $tw.utils.getAnimationDuration(),
removeElement = function() {
widget.removeChildDomNodes();
};
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
removeElement();
return;
}
// Get the current height of the tiddler
var currWidth = targetElement.offsetWidth,
computedStyle = window.getComputedStyle(targetElement),
currMarginBottom = parseInt(computedStyle.marginBottom,10),
currMarginTop = parseInt(computedStyle.marginTop,10),
currHeight = targetElement.offsetHeight + currMarginTop;
// Remove the dom nodes of the widget at the end of the transition
setTimeout(function() {
widget.removeChildDomNodes();
},duration);
setTimeout(removeElement,duration);
// Animate the closure
$tw.utils.setStyle(targetElement,[
{transition: "none"},
Expand Down
26 changes: 20 additions & 6 deletions core/modules/storyviews/pop.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ PopStoryView.prototype.navigateTo = function(historyInfo) {
}
var listItemWidget = this.listWidget.children[listElementIndex],
targetElement = listItemWidget.findFirstDomNode();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
return;
}
// Scroll the node into view
this.listWidget.dispatchEvent({type: "tm-scroll", target: targetElement});
};

PopStoryView.prototype.insert = function(widget) {
var targetElement = widget.findFirstDomNode(),
duration = $tw.utils.getAnimationDuration();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
return;
}
// Reset once the transition is over
setTimeout(function() {
$tw.utils.setStyle(targetElement,[
Expand All @@ -55,13 +63,19 @@ PopStoryView.prototype.insert = function(widget) {

PopStoryView.prototype.remove = function(widget) {
var targetElement = widget.findFirstDomNode(),
duration = $tw.utils.getAnimationDuration();
duration = $tw.utils.getAnimationDuration(),
removeElement = function() {
if(targetElement.parentNode) {
widget.removeChildDomNodes();
}
};
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
removeElement();
return;
}
// Remove the element at the end of the transition
setTimeout(function() {
if(targetElement.parentNode) {
widget.removeChildDomNodes();
}
},duration);
setTimeout(removeElement,duration);
// Animate the closure
$tw.utils.setStyle(targetElement,[
{transition: "none"},
Expand Down
27 changes: 22 additions & 5 deletions core/modules/storyviews/zoomin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var ZoominListView = function(listWidget) {
// Make all the tiddlers position absolute, and hide all but the top (or first) one
$tw.utils.each(this.listWidget.children,function(itemWidget,index) {
var domNode = itemWidget.findFirstDomNode();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(domNode instanceof Element)) {
return;
}
if(targetTiddler !== itemWidget.parseTreeNode.itemTitle || (!targetTiddler && index)) {
domNode.style.display = "none";
} else {
Expand All @@ -43,6 +47,10 @@ ZoominListView.prototype.navigateTo = function(historyInfo) {
}
var listItemWidget = this.listWidget.children[listElementIndex],
targetElement = listItemWidget.findFirstDomNode();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
return;
}
// Make the new tiddler be position absolute and visible so that we can measure it
$tw.utils.setStyle(targetElement,[
{position: "absolute"},
Expand Down Expand Up @@ -121,6 +129,10 @@ function findTitleDomNode(widget,targetClass) {

ZoominListView.prototype.insert = function(widget) {
var targetElement = widget.findFirstDomNode();
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
return;
}
// Make the newly inserted node position absolute and hidden
$tw.utils.setStyle(targetElement,[
{display: "none"},
Expand All @@ -130,7 +142,15 @@ ZoominListView.prototype.insert = function(widget) {

ZoominListView.prototype.remove = function(widget) {
var targetElement = widget.findFirstDomNode(),
duration = $tw.utils.getAnimationDuration();
duration = $tw.utils.getAnimationDuration(),
removeElement = function() {
widget.removeChildDomNodes();
};
// Abandon if the list entry isn't a DOM element (it might be a text node)
if(!(targetElement instanceof Element)) {
removeElement();
return;
}
// Set up the tiddler that is being closed
$tw.utils.setStyle(targetElement,[
{position: "absolute"},
Expand Down Expand Up @@ -170,10 +190,7 @@ ZoominListView.prototype.remove = function(widget) {
{opacity: "0"},
{zIndex: "0"}
]);
setTimeout(function() {
// Delete the DOM node when the transition is over
widget.removeChildDomNodes();
},duration);
setTimeout(removeElement,duration);
// Now the tiddler we're going back to
if(toWidgetDomNode) {
$tw.utils.setStyle(toWidgetDomNode,[
Expand Down
2 changes: 2 additions & 0 deletions editions/tw5.com/tiddlers/widgets/ListWidget.tid
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The `storyview` attribute specifies the name of an optional module that can anim
* `zoomin`: just renders the current tiddler from the list, with a zoom animation for navigating between tiddlers
* `pop`: shrinks items in and out of place

In order for the storyviews to animate correctly each entry in the list should be a single block mode DOM element.

!! Handling history and navigation

The optional `history` attribute specifies the name of a tiddler that is used to track the current tiddler for navigation purposes. When the history tiddler changes the list view responds by telling the listview to handle navigating to the new tiddler. See the NavigationMechanism for more details.
Expand Down

0 comments on commit 115245a

Please sign in to comment.