browse by category or date

jQuery makes a lot of things easier. I have blogged before about creating collapsible/expandable box. But jQuery make that blog post obsolete and too ‘dirty’.

After consulting with Google, it pointed out a great website that teaches tips & tricks on Javascript. I modified his project to suit what I need. Below is the code, and after it, you could find the Live Demo.

 

Original Code

<html>
	<head>
		<title>Test JQuery</title>
		<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
		<script type="text/javascript">
			$(function() {
			$('div.sdvExp')
				.css("cursor","pointer")
				.attr("title","Click to expand/collapse")
				.click(function(){
					$(this).siblings('.child-'+this.id).toggle();
				});
			$('div[class^=child-]').hide();
		});
		</script>
	</head>
	<body>
		<div class="sdvExp" id="div1">
			<p>Lorem Ipsum</p>
		</div>
		<div class="child-div1">
			Lorem ipsum dolor sit amet, consectetur adipiscing elit. In at commodo tortor. Donec condimentum rutrum dui,
			vitae rutrum dolor malesuada a. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac
			turpis egestas. Donec facilisis ligula eu risus cursus cursus. Curabitur nec bibendum nulla. 
			Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. 
			Vivamus eu dolor et enim egestas pellentesque ac a sapien. Maecenas aliquam adipiscing fermentum.
			Quisque egestas dui sed lacus congue id sagittis urna mattis. Duis ut cursus libero. 
			Pellentesque lorem neque, fermentum sed fermentum at, auctor et nisl. Nulla lobortis elit odio. 
			Suspendisse laoreet volutpat adipiscing.
		</div>
	</body>
</html>

Live Demo

Expandable/Collapsible Box Demo
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In at commodo tortor. Donec condimentum rutrum dui, vitae rutrum dolor malesuada a. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec facilisis ligula eu risus cursus cursus. Curabitur nec bibendum nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus eu dolor et enim egestas pellentesque ac a sapien. Maecenas aliquam adipiscing fermentum. Quisque egestas dui sed lacus congue id sagittis urna mattis. Duis ut cursus libero. Pellentesque lorem neque, fermentum sed fermentum at, auctor et nisl. Nulla lobortis elit odio. Suspendisse laoreet volutpat adipiscing.

Making it Work in WordPress

To make the box working in WordPress, please observe the following source code and follow the three steps:

<!-- STEP 1: Create the control DIV. Its class name should be sdvExp. It also must have an ID (e.g. sdvExp1958) -->
<div class="sdvExp" style="background:#333;border:1px" id="sdvExp1958"><p>Expandable/Collapsible Box Demo</p></div>

<!-- STEP 2: Create the content DIV. Its class name should be child-{control-div-ID} (e.g. child-sdvExp1958) --> 
<div class="child-sdvExp1958">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In at commodo tortor. Donec condimentum rutrum dui, vitae rutrum dolor malesuada a. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec facilisis ligula eu risus cursus cursus. Curabitur nec bibendum nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus eu dolor et enim egestas pellentesque ac a sapien. Maecenas aliquam adipiscing fermentum. Quisque egestas dui sed lacus congue id sagittis urna mattis. Duis ut cursus libero. Pellentesque lorem neque, fermentum sed fermentum at, auctor et nisl. Nulla lobortis elit odio. Suspendisse laoreet volutpat adipiscing.
</div>

<!-- STEP 3: Add the following code -->
<script type="text/javascript" src="https://sodeve.net/js/sodeve.expander.js"></script>

If you follow three steps above, you should get your expandable/collapsible box working.

Good luck!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

Arrival of something beautiful
Instantly captures the hearts of many
Radiant, your smile is
Enchanting, your eyes are
Natural fair, your complexion is

Alhamdulillah …
Islam is your faith
Shahadah is your declaration
Hadits after Al-Qur’an, is your life guidance
Akhlakul Karimah is your personality

After 9 months of journey, you came among us
Regardless what the Doctor predicted, you have your own will
Instead of 28 October, you pick 18 October
Far away, I was startled and surprised
All my projects, tasks, I immediately left them behind
Nevertheless, I couldn’t witness your miraculous birth
Thanks to God, for the safety and health of you, and your mother
Only to God, we worship. And only to God we ask for help

Welcome to the world, my beautiful daughter–Airen Aisha Arifanto. Your Dad and your Mom always pray that you become a beautiful, healthy, intellectual, strong and pious muslimah with akhlakul karimah.. Amiiien…

42

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

As your blog become more visible to the search engines’ bot, it is also become more visible to the spammer-bots (spambots). A spambot is a program designed to promote shady websites, sell dubious health products, sell counterfeit goods annoy and slow down your database.

Usually, spambots is run in a botnet. Botnet is a network which consists of computers that are controlled by black-hat hackers. If suddenly your friends complained that you send them spammy messages from your email/instant Messenger, check your PC. Your PC may already become a botnet members.

Back to the topic of this post, this blog is used to be plagued by many spam comments/trackbacks. But with my recent configuration, I am confident that it will able to thwart most of the spam comments without causing too much of irritation to the good visitors of this blog.

If you think your WordPress blog is currently being targeted by spammers, you should try these two WordPress plugins will keep them at the bay:

1. Akismet

Akismet works by intercepting all submitted comments & trackback. It will submit the comments and trackbracks to their web service for test. If the result turns out positive, it will allow the comments/trackback. If negative, they will go to spam folder. I highly recommended you to use Akismet.

2. Spam Free WordPress

Although Akismet is good, it’s not enough. With Akismet, the comments/trackbacks are still be saved in the database anyway. So if you have many spambots posting comments to your blog, it could slow down your blog. Because of that, I recently deployed Spam Free WordPress. This plugin works by generating a unique password for each post. This way, a spambot can’t directly hit you with a FORM submit. Instead, it needs to download the whole page, parse the HTML, extract out the password, and finally submit the FORM.

So yes, this plugin has a weakness. But parsing a whole page is not economical to the spammers, so this plugin will deter most of the spammers. But if they somehow managed to submit the spammy comments/trackbacks, Akismet will be ready to catch them and throw these SOB to the spam folder.

Conclusion

Once you have these two plugins deployed in your blog, your blog will have two security layers to defend from spambots attacks. On the outer layer you have Spam Free WordPress plugin that requires the bot to read the post before posting. And there’s Akismet standing behind, ready to catch any comments/trackbacks that managed to bypass Spam Free WordPress.

Goodluck with your blog!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: