What's been happening?

April 15th, 2008

Posted at 12:00am by Stan

The Higher Things website uses a really cool jQuery plugin called Superfish for it's black navigational bar. I first stumbled across this plugin while dealing with an animation problem for a home-grown implementation when we were redesigning the site. Rather then re-invent the wheel I decided to just use Superfish. One of the things that I was never really keen on was the lack of an animation to close the menu when, it just disappears as opposed to when it appears it slides in to view.

As a result I've modified superfish for HT's website and thought I would share the hack here for anyone else interesting in getting superfish to animate when a menu item closes.

First, we need to change some options around, we're going to remove the "defaults" for "animation" and replace it with the following (this should be at line 20):

animationOpen : {opacity:'show'}, animationClose : {opacity:'hide'},

Second, around line 78 we need to change how the method responsible for hiding a superfish menu functions, replace the "hideSuperfishUl" and "showSuperfishUl" method with this one:

hideSuperfishUl : function(){ var o = $.superfish.op, $ul = $('li.'+o.hoverClass,this).add(this); $ul.find('>ul').animate(o.animationClose, o.speed, function() { $(this).css('visibility','hidden'); $ul.removeClass(o.hoverClass); o.onBeforeShow.call($ul); }); return this; }, showSuperfishUl : function(){ var o = $.superfish.op, $ul = this.addClass(o.hoverClass) .find('>ul:hidden').css('visibility','visible'); o.onBeforeShow.call($ul); $ul.animate(o.animationOpen,o.speed,function(){ o.onShow.call(this); }); return this; }

That's it! I set the above defaults following the release to use opacity for animating, however on HT's we use { height: 'show' } and { height: 'hide' } respectively for the animations. You'll note in the hide method we added an animation and then after that animation has finished executing, in a call back we remove the hover class and call the closing callback. In the show method all we did was change the name of the animation property to be used, since we now have two.

March 29th, 2008

Posted at 12:00am by Stan

Earlier today I release jGrowl 1.0.2 on the jQuery plugin page, and I also uploaded the release locally as well. This release is bundled into a zip file and contained within it is a demo page and an accompanying stylesheet. There are some pretty substantial changes in this release, including...

  • Styling is now done externally, not inline.
  • Messages can have an optional "theme" passed in, which defines secondary classes to be applied to messages. This allows for messages to be themed on a per-message basis.
  • Animation speed can be customized.
  • The global closer can be disabled.
  • Added an optional callback to the global closer.
  • Added an optional open and close callback to the individual notifications.
  • Customize the life of a message on a per-message basis.
  • jGrowl automatically starts itself up with the first message.
  • When there are no messages jGrowl will automatically shut itself down.
  • ...fixed various bugs in 1.0.1.

Overall this release is quite a bit better then the previous one. If you have any ideas for future features, or if you discover any bugs please feel free to contact me.

The new release can be downloaded at: http://stanlemon.net/files/jgrowl-1.0.2.zip

March 22nd, 2008

Posted at 12:03am by Stan

I just setup jQuery Templates and jGrowl in the jQuery plugin repository, and then I added them on my own projects page. I'll try and keep the plugin page's release piece up to date as I make modifications, and I also promise to do my best in following up on any bugs reported.

March 21st, 2008

Posted at 10:59pm by Stan

I just uploaded a new copy of jQuery templates with a fix for $.fn.text() and $.fn.html(), I was not passing the options object in correctly (silly mistake) and thanks to Chris Jaure, if you were using either of these methods to simply return a value they now work correctly as well.

jQuery Templates available at: http://stanlemon.net/files/jquery.template.js

March 20th, 2008

Posted at 11:36pm by Stan

Growl

Back in November I wanted a mechanism to communicate messages after an ajax request to my PageSite users. I experimented with a number of things and initially had a terribly ugly manipulation of the green and red message boxes you'll see on this type from time to time. There were a couple of big problems though, first the code was originally written for Prototype so it sucked, and second it was not very portable. Ultimately I wanted something that looked good, was well written and could be reused in a number of different ways.

When PageSite was converted to using jQuery for all of its javascript I rehashed a lot of stuff. There was some old javascript code that had been floating around since 2004 when I first prototyped out PageSite 4.0's admin panel. To cut to the chase... I stumbled across Humanized Messages, which was close to what I wanted to do, but not yet there. This plugin got me to thinking, though, what I'd really like is something that looked like Growl. For those not on OS X, take a look at the website and you'll see that Growl is a system-wide notification system.

As a result, while Erich was out here visiting I fleshed out an initial concept. I called it jGrowl, spinning off of the OS X solution. It's pretty simple to use out of the box:

// Normal notification $.jGrowl("Here is my message!"); // Sticky notification $.jGrowl("This message is stuck!", { sticky: true });

Today I sat down and cleaned up some of the plugin, namely I removed a dependency on the metadata plugin in favor of $.fn.data() and I also namespaced all of the events, which should allow you to attach other events to the jGrowl nodes and deal with them without jGrowl unbinding them on you.

The plugin still needs some work, I'm not sure how much I like styling it with javascript - at the same rate, I like the idea of styling different notifications differently as well. I'd also like to see some callback options, the animations customizable and I'd like to potentially add some internal sorting using the "header" option. These things, though, will come in time - for now I just want to get the plugin out so I can get some feedback.

Updated 03/24/08: The plugin is available at: http://stanlemon.net/files/jgrowl-1.0.2.zip, please let me know what you think!

March 20th, 2008

Posted at 12:27pm by Stan

As I continue to get feedback on the jQuery Templates plugin I've ported from Ext I'm trying to implement the suggestions I've received. Subsequently, I've uploaded another round (or two) of changes. The changes I've made are:

  • Moved the $template object to $.template.instance, so that the object can be access from the jQuery object and extended easily - what was I thinking before??
  • Renamed the "re" property to "regx", and this is now an object containing several different regular expression options (jsp, jtemplates and ext for starters).
  • You can now change the standard regular expression by setting $.template.regx.standard = $.template.regx.myregexp;
  • Templates can utilize custom regular expressions on a per-template basis, ie. var t = $.template("<div>...</div>", { regx: 'ext' });
  • In addition to the methods that use domManip() I've updated html() and text() to handle receiving jQuery Templates as well.

I hope to add some kind of callback to the plugin as well, so that you can specify a method to be called after a template has been created or applied. I'm still thinking this through and will post more once I implement it.

March 12th, 2008

Posted at 11:43pm by Stan

I've done some more work on my jQuery Templates proposal. First, by request from some on the jQuery lists I've removed the usage of the $.ui namespace, although it really functioned completely independent of jQuery.UI. Second, I've added a modification to override the jQuery domManip() method, which is a method called by other methods like insertBefore() and append() and handle DOM manipulation within the jQuery core. Now, you can pass any of the manipulation methods your jQuery Template object and as a second parameter the object of properties for replacement. This changes the syntax to:

var t = $.template('
Hello ${name}, how are you ${question}? I am ${me:substr(0,10)}
'); $(selector).append( t , { name: 'Stan', question: 'feeling', me: 'doing quite well myself, thank you very much!' });

I'm going to resubmit my proposal to jquery-en and jquery-ui for consideration and review. If you're interested in looking at the code, it's available at:
http://stanlemon.net/files/jquery.template.js

February 22nd, 2008

Posted at 10:48am by Stan

Some conversation at work arose about templating in jQuery. The honest answer to anyone inquiring about this is that jQuery lacks any real good solution for simple macro-based templating. I was directed to Ext, which has a Template library in it that does exactly this. Subsequently, I've proposed to the UI folk a port of Ext.Template. For the most part the port is direct, the apply() and compile() methods are virtually identical to Ext.Template, though they use some jQuery functions instead of Ext.Core functions. The constructor is very different, and the designation of compiling is via a jQuery-style options object passed to the template constructor. I've tried to follow the jQuery.UI API as best as I know. I've changed the formatter usage in Ext.Template, as it depends on Ext.util.Format which isn't available in jQuery. All in all, this functionality does not seem like it's necessary so I changed it to use what I'm calling "helpers". These helpers provide the variable:method() syntax like in Ext.Template but allows the designer to customize what functions are available in a jQuery-style way.

Updated 03/12/2008: Anyhow, the code for my port and proposal is available here:
http://stanlemon.net/files/jquery.template.js

Powered by BlogSCL3 0.2.0alpha