For my next stuff I needed the Javascript equivalents of PHP functions basename() and dirname(). Nothing genius: PLAIN TEXT JAVASCRIPT: function basename(path) { return path.replace(/\\/g,'/').replace( /.*\//, '' ); } function dirname(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');; } It obviously supports paths like /home/ozh/stuff.php, http://site.com/file.ext or double backslashed Win32 paths such as C:\\dir\\document.txt. Edit: Mister Ze in comments points out to [...] → Read more
Archive for the "Javascript" Tag
Adding javascript into an admin page is a critical part of plugin coding. Critical, because it is both trivial and probably reason #1 why it will conflict with other plugins if not done properly. When their plugin needs javascript, Good Plugin Coders™ have to make sure of the following points: add javascript only once: if you [...] → Read more
Sometimes, you stumble upon a cool Flickr photo and only know its static URL (something like 14488551_4945c8ea17_b.jpg). You'd like to go to the photo Flickr page (ie this), to know more about the author, and discover other pictures of the same kind? Bookmark this bookmarklet: Flickr Photo Page Quick explanation: Flickr image filenames in static URLs are [...] → Read more
Early 2006, a cool guy named Lokesh Dhakar introduced Lightbox, a unobtrusive script used to display large images using modal dialogs over a black faded background. A great script, really. Since, every once in a while, someone comes up with their own take at this concept, using this or that javascript library (jQuery, Prototype, Mootools, [...] → Read more
Pretty Comments is a tiny (1kb) jQuery plugin that makes textareas grow as content goes in. This should make a pretty cool addition to any jQuerified comment form. I think I'll add this here to my own theme when I have some time to do some coding in order to get rid of Prototype. Share This Related [...] → Read more
Remove All Facebook Ads: the only Greasemonkey script for Facebook you'll really need. No more adds in pages and sidebar, or "sponsored" items in news feed. Share This Related posts The Next Big Thing : Ajax (0) Switzerland Map (1) Putting some fun in the layout (0) Pretty Comments: Increase your Textarea as you Type (1) Javascript Console in Firefox’ Sidebar (0) [...] → Read more
This is pure awesomeness. Instant.js is an 8.5 kb javascript file (uncompressed, you can shrink it down to around 5 kb) which adds on the fly a "Polaroid Effect" to your pictures (white frame, light curl and a drop shadow). What I like about this is the unobstrusiveness (?) and the fact it does not [...] → Read more
Today I felt like tidying a bit Planet Wordpress, an unofficial aggregation of feeds about Wordpress I've been maintaining for about 2 years now. The thing was fetching about 80 feeds, of which about a half were... dead, missing in action, or just inactive. It quickly appeared to me than manually reviewing 80 feeds would be [...] → Read more
Impressive : add a single javascript line from JS-Kit and you get a full comment system without any other coding or server side stuff needed. There are even several options and settings, and the whole comment engine is Akismet enabled to make sure you get no spam. I'm not sure how convenient and easy things are [...] → Read more
Situation : You want to insert some simple content into a DOM element. Since you happen to be a javascript n00b like me who always forget how to do it, and you don't want to use a 60 kb prototype.js for your 10 javascript lines project, you thought it would be useful to write down [...] → Read more