2007-03-30 04:36:52 +00:00
|
|
|
/*
|
|
|
|
|
* ToDo Items
|
|
|
|
|
*
|
|
|
|
|
* Requires the prototype.js library
|
|
|
|
|
*
|
|
|
|
|
* Use the following markup to include the library:
|
|
|
|
|
* <script type="text/javascript" src="todo-items.js"></script>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ToDoItems = Class.create();
|
|
|
|
|
|
|
|
|
|
ToDoItems.prototype = {
|
2008-06-06 19:37:07 +00:00
|
|
|
initialize: function()
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
/* keep track of last effect so you can check if the animation has finised */
|
|
|
|
|
this.lastEffect= null;
|
|
|
|
|
this.initialized = true;
|
|
|
|
|
this.contextCollapseCookieManager = new CookieManager();
|
|
|
|
|
this.toggleItemsMap = {};
|
|
|
|
|
this.toggleContainerMap = {};
|
|
|
|
|
this.containerItemsMap = {};
|
|
|
|
|
},
|
|
|
|
|
addNextActionListingToggles: function()
|
|
|
|
|
{
|
|
|
|
|
this.containerToggles = $$('.container_toggle');
|
|
|
|
|
containerTogglesClick = this.toggleNextActionListing.bindAsEventListener(this);
|
|
|
|
|
for(i=0; i < this.containerToggles.length; i++)
|
|
|
|
|
{
|
|
|
|
|
toggleElem = this.containerToggles[i];
|
|
|
|
|
containerElem = toggleElem.parentNode.parentNode
|
|
|
|
|
itemsElem = $(containerElem.id).select("div#"+containerElem.id+"items")[0];
|
|
|
|
|
this.toggleContainerMap[toggleElem.id] = containerElem;
|
|
|
|
|
this.toggleItemsMap[toggleElem.id] = itemsElem;
|
|
|
|
|
this.containerItemsMap[containerElem.id] = itemsElem;
|
|
|
|
|
}
|
2007-03-30 04:36:52 +00:00
|
|
|
this.setNextActionListingTogglesToCookiedState();
|
2008-06-06 19:37:07 +00:00
|
|
|
},
|
|
|
|
|
setNextActionListingTogglesToCookiedState: function()
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
for(i=0; i < this.containerToggles.length; i++)
|
|
|
|
|
{
|
|
|
|
|
toggleElem = this.containerToggles[i];
|
|
|
|
|
containerElem = this.toggleContainerMap[toggleElem.id];
|
|
|
|
|
collapsedCookie = this.contextCollapseCookieManager.getCookie(this.buildCookieName(containerElem));
|
|
|
|
|
itemsElem = this.toggleItemsMap[toggleElem.id];
|
|
|
|
|
isExpanded = Element.visible(itemsElem);
|
|
|
|
|
if (collapsedCookie && isExpanded)
|
|
|
|
|
{
|
|
|
|
|
this.collapseNextActionListing(toggleElem, itemsElem);
|
|
|
|
|
}
|
|
|
|
|
else if (!collapsedCookie && !isExpanded)
|
|
|
|
|
{
|
|
|
|
|
this.expandNextActionListing(toggleElem, itemsElem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
collapseAllNextActionListing: function(except)
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
for(i=0; i < this.containerToggles.length; i++)
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
toggleElem = this.containerToggles[i];
|
|
|
|
|
if (toggleElem != except)
|
|
|
|
|
{
|
|
|
|
|
itemsElem = this.toggleItemsMap[toggleElem.id];
|
|
|
|
|
isExpanded = Element.visible(itemsElem);
|
|
|
|
|
if (isExpanded)
|
|
|
|
|
{
|
|
|
|
|
this.collapseNextActionListing(toggleElem, itemsElem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-30 04:36:52 +00:00
|
|
|
}
|
2008-06-06 19:37:07 +00:00
|
|
|
},
|
|
|
|
|
ensureVisibleWithEffectAppear: function(elemId)
|
|
|
|
|
{
|
2007-03-30 04:36:52 +00:00
|
|
|
if ($(elemId).style.display == 'none')
|
|
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
new Effect.Appear(elemId,{duration:0.4});
|
2007-03-30 04:36:52 +00:00
|
|
|
}
|
2008-06-06 19:37:07 +00:00
|
|
|
},
|
|
|
|
|
fadeAndRemoveItem: function(itemContainerElemId)
|
|
|
|
|
{
|
2007-03-30 04:36:52 +00:00
|
|
|
var fadingElemId = itemContainerElemId + '-fading';
|
|
|
|
|
$(itemContainerElemId).setAttribute('id',fadingElemId);
|
|
|
|
|
Element.removeClassName($(fadingElemId),'item-container');
|
|
|
|
|
new Effect.Fade(fadingElemId,{afterFinish:function(effect) { Element.remove(fadingElemId); }, duration:0.4});
|
2008-06-06 19:37:07 +00:00
|
|
|
},
|
|
|
|
|
toggleNextActionListing: function(event)
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
Event.stop(event);
|
|
|
|
|
toggleElem = Event.element(event).parentNode;
|
|
|
|
|
itemsElem = this.toggleItemsMap[toggleElem.id];
|
|
|
|
|
containerElem = this.toggleContainerMap[toggleElem.id];
|
|
|
|
|
if (Element.visible(itemsElem))
|
|
|
|
|
{
|
|
|
|
|
this.collapseNextActionListing(toggleElem, itemsElem);
|
|
|
|
|
this.contextCollapseCookieManager.setCookie(this.buildCookieName(containerElem), true)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.expandNextActionListing(toggleElem, itemsElem);
|
|
|
|
|
this.contextCollapseCookieManager.clearCookie(this.buildCookieName(containerElem))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
findToggleElemForContext : function(contextElem)
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
childElems = $A($(contextElem).getElementsByTagName('a'));
|
|
|
|
|
return childElems.detect(function(childElem) { return childElem.className == 'container_toggle' });
|
|
|
|
|
},
|
|
|
|
|
expandNextActionListing: function(toggleElem, itemsElem, skipAnimation)
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
itemsElem = $(itemsElem)
|
|
|
|
|
if (skipAnimation == true) {
|
|
|
|
|
itemsElem.style.display = 'block';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.lastEffect = Effect.BlindDown(itemsElem, { duration: 0.4 });
|
|
|
|
|
}
|
|
|
|
|
toggleElem.setAttribute('title', 'Collapse');
|
|
|
|
|
imgElem = this.findToggleImgElem(toggleElem);
|
2007-03-30 04:36:52 +00:00
|
|
|
imgElem.src = imgElem.src.replace('expand','collapse');
|
2008-06-06 19:37:07 +00:00
|
|
|
imgElem.setAttribute('title','Collapse');
|
|
|
|
|
},
|
|
|
|
|
ensureContainerHeight: function(itemsElem)
|
|
|
|
|
{
|
|
|
|
|
itemsElem = $(itemsElem);
|
|
|
|
|
Element.setStyle(itemsElem, {height : ''});
|
|
|
|
|
Element.setStyle(itemsElem, {overflow : ''});
|
|
|
|
|
},
|
|
|
|
|
expandNextActionListingByContext: function(itemsElem, skipAnimation)
|
|
|
|
|
{
|
|
|
|
|
contextElem = this.findNearestParentByClassName($(itemsElem), "context");
|
|
|
|
|
toggleElem = this.findToggleElemForContext(contextElem);
|
|
|
|
|
this.expandNextActionListing(toggleElem, itemsElem, skipAnimation);
|
|
|
|
|
},
|
|
|
|
|
collapseNextActionListing: function(toggleElem, itemsElem)
|
|
|
|
|
{
|
|
|
|
|
this.lastEffect = Effect.BlindUp(itemsElem, { duration: 0.4});
|
|
|
|
|
toggleElem.setAttribute('title', 'Expand');
|
|
|
|
|
imgElem = this.findToggleImgElem(toggleElem);
|
|
|
|
|
imgElem.src = imgElem.src.replace('collapse','expand');
|
2007-03-30 04:36:52 +00:00
|
|
|
imgElem.setAttribute('title','Expand');
|
2008-06-06 19:37:07 +00:00
|
|
|
},
|
|
|
|
|
findToggleImgElem: function(toggleElem)
|
|
|
|
|
{
|
|
|
|
|
childImgElems = $A(toggleElem.getElementsByTagName('img'));
|
|
|
|
|
return childImgElems[0];
|
|
|
|
|
},
|
|
|
|
|
buildCookieName: function(containerElem)
|
|
|
|
|
{
|
2007-03-30 04:36:52 +00:00
|
|
|
tracks_login = this.contextCollapseCookieManager.getCookie('tracks_login');
|
2008-06-06 19:37:07 +00:00
|
|
|
return 'tracks_'+tracks_login+'_context_' + containerElem.id + '_collapsed';
|
|
|
|
|
},
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2008-06-06 19:37:07 +00:00
|
|
|
findNearestParentByClassName: function(elem, parentClassName)
|
|
|
|
|
{
|
2007-03-30 04:36:52 +00:00
|
|
|
var parentElem = elem.parentNode;
|
|
|
|
|
while(parentElem)
|
|
|
|
|
{
|
2008-06-06 19:37:07 +00:00
|
|
|
if (Element.hasClassName(parentElem, parentClassName))
|
|
|
|
|
{
|
|
|
|
|
return parentElem;
|
|
|
|
|
}
|
|
|
|
|
parentElem = parentElem.parentNode;
|
2007-03-30 04:36:52 +00:00
|
|
|
}
|
|
|
|
|
return null;
|
2008-06-06 19:37:07 +00:00
|
|
|
}
|
2007-03-30 04:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
todoItems = new ToDoItems();
|
|
|
|
|
Event.observe(window, "load", todoItems.addNextActionListingToggles.bindAsEventListener(todoItems));
|