QuicksearchShow tagged entriesCategories |
Wednesday, June 24. 2009
jQuery simple unordered list filter Posted by Mark van der Velden
in Javascript at
15:50
Comments (6) Trackbacks (0) jQuery simple unordered list filterI needed a simple filter system on a unordered list. The goal is to filter 'realtime' based on what a user is typing. I came up with the following, if you have any suggestions and/or performance tips feel free to drop a line! The HTML:The blog software is messing with the HTML, for a working example with ungarbled code. Look at the bottom of this post.
</p><div> <input name="filter" id="search_filter" type="text"> </div><div id="titles"> <ul> <li><a href="http://blog.dynom.nl/path/to/item/1">Item 1</a></li> <li><a href="http://blog.dynom.nl/path/to/item/2">Item 2</a></li> <li><a href="http://blog.dynom.nl/path/to/item/3">Item 3</a></li> </ul> </div>
The Javascriptvar My = {}
My.List = { Filter : function (inputSelector, listSelector) { // Sanity check var inp, rgx = new RegExp(), titles = $(listSelector), keys; if (titles.length === 0) { return false; } // The list with keys to skip (esc, arrows, return, etc) // 8 is backspace, you might want to remove that for better usability keys = [ 13, 27, 32, 37, 38, 39, 40, 8 ]; // binding keyup to the unordered list $(inputSelector).bind('keyup', function (e) { if (jQuery.inArray(e.keyCode, keys) >= 0) { return false; } // Building the regex from our user input, 'inp' should be escaped inp = $(this).attr('value'); rgx.compile(inp, 'im'); titles.each(function () { if (rgx.source !== '' && !rgx.test($(this).html())) { $(this).parent('li').hide(); } else { $(this).parent('li').show(); } }); }); } }; // When the DOM is ready $(document).ready(function () { // Attach the filter to our input and list My.List.Filter('input#search_filter', '#titles>ul>li>a'); }); Working exampleVisit http://dynom.nl/jquery/list.php for a working example. Tuesday, May 26. 2009
Javascript cookie helper class Posted by Mark van der Velden
in Javascript at
12:00
Comments (2) Trackbacks (0) Javascript cookie helper classLittle original perhaps, but I thought I'd share this cookie class. It makes my life a little easier, My.Cookie = {
/** * Set a cookie * @param {string} n name * @param {scalar} v value * @param {int} days */ set: function (n, v, days) { var e = '', d; if (days) { d = new Date(); d.setTime(d.getTime() + (days * 86400000)); e = "; expires=" + d.toGMTString(); } document.cookie = n + "=" + v + e + "; path=/"; }, /** * get a cookie * @param {string} n name */ get: function (n) { var match = n + "=", c = '', ca = document.cookie.split(';'), i; for (i = 0; i < ca.length, c=ca[i]; i++) { if (c.indexOf(match) === 0) { return c.substring(match.length, c.length); } } return null; }, /** * Delete a cookie * @param {string} n name */ del: function (n) { this.set(n, "", -1); } }; Thursday, May 14. 2009
PHP Quiz part 2 Posted by Mark van der Velden
in PHP, PHPQuiz, PlanetPHP at
10:41
Comments (13) Trackbacks (0) Defined tags for this entry: arrayaccess, nesting structures, operator precedence, php, php quiz, phpquiz, planetphp, references
PHP Quiz part 2A short quiz this time, but that doesn't make it less fun. Do you know the answer to all of them? Get a cup of coffee and kill 10 minutes with round two... As always, think of the answer before you execute the code or look it up. You can find round one here. Array pointerWhat will the output be ? ArrayAccess and isset funisset or not isset, thats the question. $a = new ArrayObject;
$a['fubar'] = NULL; $null = NULL; if (isset($null)) { echo 1; } else { echo 2; } if (isset($a['fubar'])) { echo 1; } else { echo 2; } if (array_key_exists('fubar', $a)) { echo 1; } else { echo 2; } Typo?The output might be confusing.. ReferencesHow many notices will be thrown? Monday, May 11. 2009
Javascript unordened list sorting Posted by Mark van der Velden
in Javascript at
15:19
Comment (1) Trackbacks (0) Defined tags for this entry: ajax, bubble sort, javascript, jquery, li, natural sort, ul, unordened list
Javascript unordened list sortingI spent some time figuring out a way to sort unordened lists, when dynamically (AJAX) adding/removing items. I had some problems with the typical '10 being greater then 1, but lesser then 2', so I took a simple bubblesort algorithm and tweaked it with the string length. It's probably not the fastest or most elegant way of doing it, but it works like a charm. If you have any improvement points, don't be shy and drop a line.
The algorithm:
// Search algorithm, if lesser then 0 it's smaller then the current item. // If it's greater then 0, it's "larger" then the current item. cmpr = ( (newItem > curListItem) - (curListItem > newItem) + (newItem.length - curListItem.length) ); Before: Title 1, Title 10, Title 13, Title 2, Title 3, Title 4 After: Title 1, Title 2, Title 3, Title 4, Title 10, Title 13
Wednesday, April 15. 2009
Zend framework reminders Posted by Mark van der Velden
in PHP at
15:00
Comments (0) Trackbacks (0) Defined tags for this entry: php, zend framework
Zend framework remindersHere a few of those "how did that work again" things, in Zend framework. Mostly for myself but hey, I'm not greedy. If you know some new/nifty ones, feel free to leave a comment! Loading a view from a different directorypublic function someAction() { // Option one $titleView = new Zend_View(); $titleView->setScriptPath( APPLICATION_PATH .'views/scripts/'); // Option two $titleView = new Zend_View(array('scriptPath'=>APPLICATION_PATH .'views/scripts/')); $viewResult = $titleView->render('_my_view_script.phtml'); } Tuesday, November 11. 2008
Did you know... part one Posted by Mark van der Velden
in PHP, PlanetPHP at
21:59
Comments (0) Trackbacks (0) Defined tags for this entry: @, datetime, empty, mod_expire, mod_headers, pecl_http, php, planetphp, scream, shutup, webgrind, writable directories
Did you know... part oneIn this blog post I'd like to talk a bit about some "Did you know's". With these "Did you know" blog posts I want to tell you a few things that I came across along the way and hopefully you know some I don't know yet! Some DYK's are directly code related, others are just here to give you insight and some are just to let you know of it's existence (Afteral you don't search for what you don't know about.) So here they come in random/chaotic order: Writable directoriesNot so PHP specific, but often miss-used is checking for writable directories/paths. Directories don't have to be readable to be used for writing, but they do have to be writable and executable. So a check like this, is simply incomplete: And will simply fail if the directory is writable but has no execute attributes (mode 0666). This is especially trouble, and can keep you occupied for a long time when using the shutup (@) parameter... Form name attribute character conversions
Friday, October 24. 2008
Best practices, part one Posted by Mark van der Velden
in PHP, PlanetPHP at
17:11
Comments (6) Trackbacks (0) Defined tags for this entry: array fun, condition order, documentation, notices, php, planetphp, variable naming, warnings
Best practices, part oneBest practices are ways of solving problems in a good way, these practices change over time and can depend on versions. A lot of people who have their roots in PHP4 have habits that are no longer best practices. But not just them, a lot of developers don't apply best-practices rules. In this blog post I'd like to point out a few reminders or refreshing points for you to take in. Most you will probably know but some you might not know or didn't look for. If you know some nice additions, make a comment and I'll add it. Enjoy! Friday, October 24. 2008
Be careful with double extensions Posted by Mark van der Velden
in PHP, PlanetPHP at
13:43
Comments (0) Trackbacks (0) Be careful with double extensionsSince I'm on a 'finish blog drafts' spree, I might as well publish this one also. I actually had it in draft for about 5 months now anyway. In most upload tools files are checked on extensions only, while it might seem pretty solid it's actually not as safe as you might think. Especially in combination with Apache and mod_mime. When you do: However when you try something like this: Before you get all excited, the scenario when this happens is not likely to happen, because it only works for unknown file extensions. So basically, this can only happen when you work with black-listing rather then white-listing. And when checking files, you shouldn't be black-listing in the first place. Let's go into detail about the why. Continue reading "Be careful with double extensions"Friday, October 24. 2008
Sucker for commandline tools, ack Posted by Mark van der Velden
in Misc at
13:28
Comments (0) Trackbacks (0) Sucker for commandline tools, ackI'm a big sucker for good command line tools, often improved version of their (often) GNU originals.
And another one: However ack has caused me some confusing moments, by default it searches only for files of a certain type. Basically meaning, it ommits files it doesn't know (by default). Small suggestion, to add -a to your .ackrc or just know what happens when you don't! I also added '.inc' in the list of php extensions, since it's commonly used. It's a brilliant tool! Even though I was a bit sceptical about it at first, and it took me some time to fully trust it (because it's much faster). It's a good asset to my daily set of tools ! Thursday, October 23. 2008
PHPMyAdmin 3.x Where are my details! Posted by Mark van der Velden
in Misc at
11:00
Comments (2) Trackbacks (0) PHPMyAdmin 3.x Where are my details!With the new PHPMyAdmin they changed a whole lot, and I like the new version! However everytime when I want to see details (like keys/indexes, etc) I needed to click on 'Details' or 'Options' to show all available details/options Probably done to save space, but I just want to see it unfold by default. I couldn't find a configuration setting for it, but I found the use of "$GLOBALS['cfg']['InitialSlidersState'] == 'closed'" somewhere (libraries/common.lib.php:2390), so I added: $cfg['InitialSlidersState'] = 'open'; To the config.inc.php and voila! If you find the correct way of doing this, let me know. In the mean while I'll use this. |
Calendar
|
|||||||||||||||||||||||||||||||||||||||||||||||||
