Your Ad Here
Aug 06

As you see on the right side I’ve many widgets and planning to add some more. But I think having so many widgets, especially if they are tall, is not visually so nice and effective. I searched for anyone who had the same problem and found Chris’s blog and his a brilliant solution,  Collapsible Widgets”.

The idea is really nice but on the other hand, setting the display style directly to none or block causes sharp and graceless transition. Hence there are many js codes for animated div transitions; I decided to go for another solution to collapse/expand the widgets with animation. After a quick search I found a handy animation on DynamicDrive.

The rest of work is just to place these js files correctly into BlogEngine and configure it. To do this, fist; add these two js files into js folder (create a new folder named as js in the webroot ) in your webapplication’s root.


Then we need to add these js files into the generated pages on runtime. BlogEngine has a nice page structure and so easy to add js files with the
AddJavaScriptInclude function in BlogEngine.Core/ Web /Controls/ BlogBasePage.cs file. Add the following lines to the BlogBasePage.cs in line 89.

 

   1:  //add JS files for animatedPanel
   2:  AddJavaScriptInclude(Utils.RelativeWebRoot + "js/jquery-1.2.2.pack.js");
   3:  AddJavaScriptInclude(Utils.RelativeWebRoot + "js/animatedcollapse.js");
   4:   
   5:  //and the original code goes on
   6:  AddJavaScriptInclude(Utils.RelativeWebRoot + "blog.js");
   7:  if (User.IsInRole(BlogSettings.Instance.AdministratorRole))


Then, we need to configure widgets to toggle theirselfs to collapse/expand. Editing App_Code/ Controls/ WidgetBase.cs as following will be enough to complate our changes.

 

   1:  if (ShowTitle)
   2:     //Change the title text to an active link to toggle collapse/expand toggle
   3:     sb.Append("<a href=\"javascript:animatedcollapse.toggle('widgetContent" + WidgetID + "')\"><h4>" + Title + "</h4></a>");
   4:          
   5:     //old title
   6:     //sb.Append("<h4>" + Title + "</h4>");
   7:  else
   8:     sb.Append("<br />");
   9:   
  10:     //Change the contentDiv and give the id starts with widgetContent
  11:     sb.Append("<div  id=\"widgetContent" + WidgetID + "\" class=\"content\">");
  12:   
  13:  writer.Write(sb.ToString());
  14:  base.Render(writer);
  15:  writer.Write("</div>");
  16:  writer.Write("</div>");
  17:   
  18:  //Initialize animatedcollapsepanel for widget.
  19:  writer.Write("<script type=\"text/javascript\"> animatedcollapse.addDiv('widgetContent" + WidgetID + "', 'fade=1'); animatedcollapse.init();</script>");


That’s all, you can see the result on my widgets by clicking their titles.

I think having smooth UI transitions and animated stuff in your webpage is not bad :)


Download the codes
: AnimatedWidgets-BlogEngine.NET.rar (21.97 kb) 

kick it on DotNetKicks.com
 

Comments

DotNetKicks.com

Posted on Wednesday, 6 August 2008 18:05

Trackback from DotNetKicks.com

Animated Collapsible/Expandable BlogEngine.NET Widgets

Gordon Breuer

Posted on Wednesday, 6 August 2008 18:26

Very nice feature! :)
But I have two proposals: First you should be able to config a widget that it is shown on first visit or not - even saving user-specified settings in a cookie might be a nice addition. The second Idea is a little symbol that makes the possibility visible to expand / minimize the widget.

Just my two cent about it :)

Muhammad Mosa

Posted on Wednesday, 6 August 2008 19:20

Yes cool one. But it would be better if we just reference jQuery hosted by Google Code.

Daniel

Posted on Wednesday, 6 August 2008 19:55

Really cool. I gonna implement it soon. It should be a part of the original widgets in the next releases.

Some.Net(Guy)

Posted on Thursday, 7 August 2008 01:09

Is there any easy way to implement the AJAX.NET accordion control with the widgets? You'd think there would be...

John

Posted on Friday, 8 August 2008 04:16

Is there even a purpose for collapsible widgets?

Personally, I've never used one.

Kivanc Ozuolmez

Posted on Friday, 8 August 2008 17:03

Hi all,

Thank you very much for your comments, please see my answers to your comments :

@Gordon, it is really nice idea to be able to configure their first-visit status. Will work on it. But on the other hand, blogs are not portals or not a personal space of a "blog reader". So, it can be a nice option to keep the widget status in cookies, but do I really want my readers to customize MY blog? (Don't take me rude)

@Muhammad, mine was a really quick and dirty implementation and we have so many other options to do the same, like Some.Net(Guy)'s idea.

@Daniel, nice, you like it.

@John, this is just an option. Some likes it some doesn't. But especially if you have many - long - widgets, I think it is just nice to have them collapsible.

Chris

Posted on Wednesday, 20 August 2008 07:38

Thanks for the reference. I recently updated my extension by switching over to JQuery and the accordion effect. Included is the ability to record your preferred open widget by placing a cookie good for your session. I would encourage you to take a look back at my site...

http://www.dscoduc.com/post/2008/08/16/AnimatedCollapse-Extension-for-Widgets.aspx

Zune

Posted on Friday, 7 November 2008 13:36

Great post. I'll try out the example code after work.

Add comment


(Will show your Gravatar icon)  

  Country flag


  • Comment
  • Preview
Loading



Software Blogs TopOfBlogs