jQuery jScrollPane Plugin: Scrolling Divs not displaying properly

March 2nd, 2010 | by: Chris Woodford

We’re just wrapping up a site for a client and they decided that they would prefer to have custom scroll bars, rather than the OS scroll bars that browsers will render by default. James did a little research and point me to the jQuery jScrollPane plugin. I took a quick look at the documentation – it looked good and seemed easy enough to implement. Once I got it into place on the site, I started to notice some problems. These problems aren’t so much related to the jScrollPane plugin, as they are to how the browser loads content.

I noticed that if I loaded a page, the scroll bars would display exactly as I would expect — however, if I did a shift+refresh, only part of the content would appear in the scrollable area. Other times, I’d notice that divs just wouldn’t appear at all.

Based on these issues and a fair amount of troubleshooting, I gathered up some important caveats for using the jScrollPane plugin.

  1. Always set a height on the div that you’re applying the scroll pane to.

    The jScrollPane plugin does a calculation to determine the height of the wrapping div that controls the scrolling. The best way that I found to ensure that the scroll bars will scroll the right amount of the content.

  2. Ensure that divs are not hidden when applying the jScrollPane

    Based on my googling, this appeared to be the most common problem that people were having. I found a few different ways to approach this problem, depending on your requirments.

    // you can explicitly set an element to show, 
    // prior to applying the scroll pane
     
    $(element).show().jScrollPane();

    OR

    // you can set the visibility to hidden, which leaves the
    // full element in the rendered page, then apply the 
    // scroll pane. After that, you can show/hide the element
    // as necessary. NB: you must reset the visibilty
     
    $(element).css('visibility', 'hidden')
    	.jScrollPane()
    	.hide()
    	.css('visibility', 'visible');

    Unfortunately I didn’t keep track of where I found these solutions, so please leave a comment if this solution is yours and I will give credit where credit is due.

  3. You may need to apply the scroll pane after the window is loaded, not just the document

    I found that when a particular div that I was using the jScrollPane on had a lot of images, using code like this:

    $(document).ready(function() {
     
    	$(element).jScrollPane();
     
    });

    would lead to only part of the content being considered scrollable, while the rest of the content was hidden. The reason here, was that the jScrollPane was calculating the height of the scrollable area, prior to the images being loaded in the div. Since the height of the images is part of what determines the final height of the div, the jScrollPane needs to be applied after the images have loaded. This is why it would load correctly when viewing a page that Firefox had already cached the images for, while doing a shift+reload (which does not use the cache) was causing only part of the content to show. My solution for this was to apply the jScrollPane once the window has loaded

    $(window).load(function() {
     
    	$(element).jScrollPane();
     
    });

    NB: depending on how long it takes for your entire page to load, you may notice some delay between the content being rendered and the scroll bars appearing. This can likely be alleviated by displaying a loading sequence until the window.load() method is called.

Hopefully these 3 points will help you avoid some common pitfalls!

Book Review — Zend Framework 1.8: Web Application Development by Keith Pope

March 1st, 2010 | by: Chris Woodford

I was recently approached by a representative from Packt Publishing to review their newst book on the Zend Framework, Zend Framework 1.8: Web Application Development by Keith Pope. The book is intended to be an introduction to the Zend Framework (ZF), and with the exception of chapters 4 and 5, I tend to agree. Chapters 4 and 5 do have their necessary place in the book, it’s just the nature of the content that leads them outside the realm of the introductory. The early chapters are a clear and concise introduction to the ZF and are even useful for the experienced ZF programmer offering a few tidbits and easier ways to do things in light of the 1.8 release. The later chapters are the most valuable for the experienced programmer and set a benchmark for the beginning programmer, showing them an example of how ZF is deployed in real world situations.

Anyone who has been following the Zend Framework and the speed at which they push out releases, may ask if this book will still be relevant. My answer to that questions is a definite yes. The 1.8 release was a milestone release for the ZF; currently at version 1.10, there haven’t been a number of signifcant changes since version 1.8. However, version 2.0 of the ZF will offer and number of changes and upgrades to a number of the core components. At that point, this book will need to be updated and improved, though just enough to get up to the 2.0 spec.

Before jumping into the review, you may want to check out the table of contents or a sample chapter.

The preface and first chapter of the book really highlight how easy it is to get a simple application up and running using the ZF. Within 3 pages of the first chapter, you’ve already got a functioning application (provided you’re following along with the examples). An important part of the first chapter, not only for programmers new to ZF but also those who are just new to the 1.8 release, is the new application configuration and the introduction of the Bootstrap classes. The way of bootstrapping applications changed pretty drastically in ZF 1.8 and you’ll see the important role is plays in development throughout chapters 1 – 4.

Chapter 2 covers all the basics of the ZF Model-View-Controller (MVC) architecture. You’ll probably need a little bit of background information about MVC architecture in order to get a full grasp of what’s going on here, but even without any knowledge of MVC, you should be able to continue following along. Really only the View and Controller ascpects are covered in any detail in Chapter 2. The Model aspect comes to light in chapter 3 and finds fruition in chapters 4 and 5. Chapters 4 and 5 start to delve outside of an introduction to the ZF and get into some of the more complex aspects of application development. In these chapters you start to see more of a picture of how Keith Pope builds a web application, which is understandable, an authors background is going to influence their writing. However I don’t think that the Service Layer pattern is strictly necessary for an introduction application development. I think that someone new to the ZF should probably re-read these chapters after reading the entire book and building at least one application. I think the importance of these chapters will come to light in retrospect.

Chapter 6 is a brief but very useful introduction to the Zend_Form component, which is arguably one of the more powerful aspects of the ZF when building web applications. While chapter 7 brings together the View aspect of the MVC showing the role that the forms play within views and really emphasising how ZF can speed up your application development. Chapters 8 and 9 cover some of the more complex parts of any web application: Authentication and Authorization. Authentication and authorization are two concepts that are often confused or conflated. Pope defines them very succintly by asking a couple simple questions to the requesting user. Authorization asks: “Can they do this?”, while Authentication asks: “Are they who they say they are?”. It’s important to keep these two concepts straight. The ZF’s concept of modules is introduced in chapter 10. Modules are a way for you to compartmentalize your application and can be reused between different applications. If your application is setup properly, modifications are only required to the application’s bootstrapping.

I found chapters 11 and 12 to be particularly useful, especially for the experienced ZF programmer. Chapter 11 covers the powerful caching that the ZF is capable of. ZF offers a number of different caching strategies, each suited to a particular purpose. Chapter 12 gets into the nitty gritty of testing. Testing is one of the most important aspects of web application development, especially when your application is live and used regularily. Pope gives a quick and handy introduction to PHPUnit (one of the most widely used testing frameworks for PHP) and then shows how ZF extends the functionality of PHPUnit. Ultimately at the end of chapter 12, you have all the tools necessary to test your entire application.

After getting through this book, you will have more than the tools necessary to build out a powerful web application using the Zend Framework. If you would like more information about the book or are interested in purachasing it, you can check it out on the Packt Publishing website

Relive The Wizard Part Deux

February 22nd, 2010 | by: James Hamilton

Relive The Wizard This February 25th
Yes, it’s that time again!

Time to find out who is Toronto’s Mario Kart King or Queen and to see if The Creeper can keep his title. This February 25th, we’ll crown the next Mario Kart King or Queen of Toronto (or The World, if that’s what you’re into). Races start at 7:30pm sharp!!!

If you’re interested in attending or entering as a contestant then RSVP here: http://www.relivethewizard.com

See everyone this Thursday.

Ian Brown Is King

February 12th, 2010 | by: James Hamilton

I cannot stop listening to Ian Brown’s “My Way.” It’s genius.

Using Zend_Soap_Client with the Campaign Monitor API

February 3rd, 2010 | by: Chris Woodford

I recently needed to write a PHP client to integrate with the SOAP side of the Campaign Monitor API. The code was pretty simple and straight-forward, but I was getting a weird error: 101 Invalid ListID. I checked and re-checked my ListID in our Campaign Monitor account and verified that I was using the correct ListID. Why then was I getting this Invalid ListID error?

After reading the Campaign Monitor API documentation a couple times, I realized that there was a specific header that I wasn’t using:

SOAPAction: "http://api.createsend.com/api/Subscriber.AddWithCustomFields"

Due to the Invalid ListID error, I wasn’t even thinking about headers! To fix the problem, all I needed to add was one line of code:

$client->addSoapInputHeader(
        new SoapHeader($soapUri, 'SOAPAction', $soapUri . $action)
    );

Then everything worked! Awesome.

Here’s a full code snippet:

 
$wsdl = 'http://api.createsend.com/api/api.asmx?wsdl';
$soapUri = 'http://api.createsend.com/api/';
$apiUri = 'http://api.createsend.com/api/api.asmx';
 
$apiKey = 'xxxxxxxxxxxxxxxxx'; // replace with your API key!
$listId = 'xxxxxxxxxxxxxxxxx'; // replace with a valid ListID! ;)
 
$action = 'Subscriber.Add';
		$method = 'AddSubscriber';
 
$client = new Zend_Soap_Client($wsdl);
$client->addSoapInputHeader(
        new SoapHeader($soapUri, 'SOAPAction', $soapUri . $action)
    );
 
$params = array ('ApiKey' => $apiKey,
		 'ListID' => $listId,
		 'Email' => 'test@offshootinc.com',
		 'Name' => 'Test Testford');
 
$response = $client->$method($params);
 
$resultName = $action . 'Result';
 
print_r($response->$resultName);

Western Union Canada Launched!

January 28th, 2010 | by: Zoe Hamilton

Today we are proud to announce the launch of the re-branded and fully operational Western Union Canada website. Check out the snaps below for a peak of the website. Better yet….click here to see the full website in action. Let us know what you think!

Western Union

Send Money

Receive Money

Find Location

Future Shop Shows Us Some Love

December 23rd, 2009 | by: James Hamilton

Future Shop Love!

A big thanks to Paul Hunter for his amazing review of the Mario Kart Tournament (aka Relive The Wizard) we held a few weeks back.

Thanks for coming out Paul and thanks again for the review.

May The Cash Money Be With You.

December 22nd, 2009 | by: James Hamilton

Amazing!

Offshoot Christmas Cookies

December 21st, 2009 | by: James Hamilton

Offshoot Cookie Jar

Lindsey Bakes! comes through again.

Zoe, great job on the packaging!

Offshoot clients, hope you enjoy your cookies.

Happy Holidays to everyone else!

Offshoot Round Cookies & Mario Block

Star and Magic Mushroom

Where did all the cookies go?

The Final Product

Ataque de Panico! + You Tube = $30 Million

December 18th, 2009 | by: Zoe Hamilton

We’ve all heard how people’s lives can change in a second because of instant fame due to You Tube or Facebook. Here’s a story about a director from Uruguay who’s landed a major deal with Hollywood because of You Tube.

A five minute short film that was done for under $1000 and uploaded to You Tube, has now landed one Uruguayan film maker a $30 million Hollywood deal.

The documentary styled short entitled Ataque de Panico! (Panic Attack!) is about gigantic robots destroying and attacking the capital of Uruguay.

Speaking with BBC Mundo the director of the short, Fede Alvarez said “I uploaded it on a Thursday and on Monday my inbox was totally full of emails from Hollywood studios…it was amazing, we were all shocked”

The $30 million dollar deal from Ghost House Pictures will team Alvarez up with a writer to create a feature film. Ghost House Pictures is the same company that hosts the Spider Man films director Sam Raimi.

It’s pretty amazing how hard work and putting yourself out there for millions to see can get you the deal of a lifetime.

Check out the full movie below.