A nice sortable trick (jQuery UI)

20 Nov

On a recent project i had to use sortable a LOT. I mean over 3-4 different sortable on page. So, how i manage to avoid heavy code?

One function to rule them all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$('.sortable').each(function(){
	var _t = $(this);
	_t.sortable({
		handle:'.move',
		items:'dd',
		update:function(){
			$.ajax({
				type: "POST",
				url: $(this).find('a.move:eq(0)').attr('href'),
				data: _t.sortable('serialize'),
				cache: false
			});
		}
	});
});

The HTML markup (for two sortables) is this:

1
2
3
4
5
6
7
8
9
10
<dl class="sortable">
	<dd id="sotableEl1-1"><a href="updateUrl.php?id=sortableID-1" class="move">move</a></dd>
	<dd id="sotableEl1-2"><a href="updateUrl.php?id=sortableID-1" class="move">move</a></dd>
	<dd id="sotableEl1-3"><a href="updateUrl.php?id=sortableID-1" class="move">move</a></dd>
</dl>
<dl class="sortable">
	<dd id="sotableEl2-1"><a href="updateUrl.php?id=sortableID-2" class="move">move</a></dd>
	<dd id="sotableEl2-2"><a href="updateUrl.php?id=sortableID-2" class="move">move</a></dd>
	<dd id="sotableEl2-3"><a href="updateUrl.php?id=sortableID-2" class="move">move</a></dd>
</dl>

This means that you don’t need to use an ID for each sortable. Instead, you add the id to the update URL, on MOVE handler (which MUST be a link). I think this is pretty simple and useful trick.

Tags: , Comments (0)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Some links

6 Nov
Tags: Comments (1)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Sunday updates

2 Nov
  • Wordpress 2.7 is out. Not final, but still a beta 1. The admin panel is AWESOME!
  • Firebug 1.3 is out. Again, this is a beta. Some of the features:

    * Net panel re-implemented, more function, no more double loads (Requires Firefox 3.0.4+)
    * Script panel rendering much faster for large Javascript files
    * Scope chain in Watches panel when stopped on breakpoint
    * Console/Command line re-implemented to avoid some undefined console problems
    * Tracing console added
    * New locales and better locale support

  • Win $700. Actually, there is ten premium wordpress themes that worth $700
  • Do you really need version control for your code? These guys convinced me i do. And bonus, review of few version control systems on smashingmagazine.
  • Absolutely FREE CSS menu framework.
Tags: Comments (0)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Very *effective* antispam trick on blogs

21 Oct

Most of bloggers have a problem with spam. Of course, there is Akismet, but sometimes Akismet is not good enough because he doesn’t catch all spam messages. So, with this in mind, i wanted only to get rid of all automated messages.

So, look what i did:

First of all, i go with „robots fills ALL fields with something” in my mind. I’ve added only TWO lines of code: one in comments.php from your theme folder and one in wp-comments-post.php from your root folder.

Ok, how you do it?

First of all you need a ftp client and a text editor. E-texteditor is 2 in 1 so you can download a trial version for doing this. Ofcourse, you can use the old and ugly notepad (or whatever your OS has default).

Open comments.php (which is in your wp-content/themes/your_theme_name folder) then find this line:

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

Some things can vary (like ID of the form), but 90% in cases you won’t need to look for something else ;)

Just AFTER this line you add:

<p style="position:absolute; left:-9999px;">Don't fill this! <input type="text" name="name2" /></p>

We put a form here and hide it. I didn’t use display:none because i wanted to be sure that field will be showed up, even is on the left side of the screen (you should actually turn you head to left to see it :P ) So the bot will actually SEE that form and will fill. Normal user won’t.

Save and upload (or just save if you work directly on ftp) then open wp-comments-post.php from your root folder. Just after the

<?php
/**
 * Handles Comment Post to WordPress and prevents duplicate comment posting.
 *
 * @package WordPress
 */

beginning part, just add this:

if( $_POST['name2']!= ''){
	die('Spammer!');
}

Save and upload.

Next you need to… Hmm… You don’t need to do anything else ! Now empty your Akismet queue and wait to see if you get any other spam messages ;)

Note that is possible to not catch ALL spams, but those are automated you won’t get it anymore :) Also, when you upgrade wordpress make sure you make those changes again. And finally, BACK UP FIRST!

Tags: , Comments (4)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

E-texteditor 1.0.31 Released

20 Oct
  • Fixed detection of correct syntax for bundle items.
  • Fixed insertion of separators in bundle menus.
  • Fixed cases where deleted bundles returned on restart.
  • Fixed completion within autobrackets.
  • Pageup/down now works in completion popup.
  • Fixed some issues with transformations in snippets.
  • Symbols are now stripped of newlines before transformation.
  • Fixed crash when opening project settings with file selected.
  • Lots of minor bugfixes.

Download free trial of E-texteditor 1.0.31 HERE.

Tags: Comments (1)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Older Posts »