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

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

Stonehenge Tours

Posted on Sunday, 18 January 2009 22:43

What a great widget... makes the site so much nice to look at. Many thanks for the post.

Lipoescultura

Posted on Friday, 6 February 2009 21:09

Is there even a purpose for collapsible widgets?

Cirurgia plastica

Posted on Friday, 6 February 2009 21:09

Thanks for the reference. I recently updated my extension by switching over to JQuery and the accordion effect.

Psicologo

Posted on Friday, 6 February 2009 21:10

Collapsible widgets sound cool.

Finance Accounting Outsourcing

Posted on Monday, 16 February 2009 22:23

I used collapsible java before in my frequently asked questions page, where if you click on a question, it collapses the the answer is displayed. Right now I don't have a lot of widgets but as soon as I do I will use your advice and that of Chris too. Thanks.

divorce lawyer in paramus

Posted on Tuesday, 17 February 2009 23:13

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

Wedding invitation boxes

Posted on Wednesday, 25 February 2009 03:28

Excellent job. I'd have to argue with you on some points but all in all very well structured article. Cheers and regards.

Philadelphia Speed Dating

Posted on Thursday, 5 March 2009 00:59

Great tutorial... really cool

Web Conferencing

Posted on Thursday, 19 March 2009 10:34

Nice widgets. This blog is very informative, you have great codes in there.

Welders

Posted on Sunday, 29 March 2009 21:29

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

Cash Advance Loans

Posted on Wednesday, 1 April 2009 03:37

Excellent article on collapsing widgets for BE.net this was what I was looking for. Thanks in advance buddy have a great day.

Franchise Blog

Posted on Thursday, 2 April 2009 12:30

Great article - the Internet is such a great medium and resource and I thank you for taking the time out to write, it is always a pleasure to read.

tnomeralc web design toys

Posted on Friday, 3 April 2009 22:12

Thank your for this tips.. Very informative, I enjoy reading your explanation..

Web Directory

Posted on Monday, 27 April 2009 07:23

Keep up the great works guys I've added you guys to my blogroll. This is a great article thanks for sharing this informative information.. I will visit your blog regularly for some latest post.

EDI

Posted on Wednesday, 29 April 2009 23:17

The collapsible widgets are really cool. Thanks for including code in your article.

Sulumits retsambew

Posted on Tuesday, 2 June 2009 14:54

this is really cool widget.. thanks

tukang nggame

Posted on Tuesday, 23 June 2009 01:54

good work, thanks for sharing the link download

Software Blogs TopOfBlogs