jQuery Mobile ajax loading spinner animation

June 11th, 2011

Some people seem to be a little bit unhappy with the way the default jQuery Mobile loading ajax spinner rotates. Luckily, this can be changed easily by contorlling the css animation settings. Here are three simple variations.

Works only in Safari and Chrome:

variation 1 (jQuery Mobile standard):

variation 2 (ease-in-out spun over multiple rotations):

variation 3 (linear):

CSS for variations 2 and 3:

.jqm-spin-demo .spin.var2 {
  -webkit-animation-name: spin_var2;
	-webkit-animation-duration: 12s;
}

@-webkit-keyframes spin_var2 {
	from {-webkit-transform: rotate(0deg);}
  	to {-webkit-transform: rotate(3600deg);}
}

.jqm-spin-demo .spin.var3 {
  -webkit-animation-timing-function: linear;
}

Phonegap 0.9.5 orientationchange javascript event

June 1st, 2011

Since Phonegap version 0.9.5 the orientationchange event is triggered on the document object instead of the window object. This might be a problem as most libraries (amongst jQueryMobile) expect the event to occur on the window object.

However, there is an easy solution (this one requires jQuery but can be easily adapted):

$(document).bind("orientationchange", function(event){
  $(window).trigger(event);
});

jfCachePlugin: two Filters that might help to make your pages cacheable (client-side)

March 6th, 2011

Today I packaged two filters I am using to manage client side caching:

  • jfCacheHeadersFilter: sets the HTTP headers required to server pages from client side (or proxy) cache
  • jfCacheInvalidateStaticSourceUrlsFilter: append a cache key to the URLs of referenced Javascript and CSS files so that you can configure a very long cache expire time for those files

Read the rest of this entry »

jfPortableDevicePlugin: Symfony to go

February 27th, 2011

I wrote a symfony plugin that allows you to easily optimize your existing symfony application for mobile devices using jQuery Mobile.
And if you want to distribute your application in Android Market or Apple App Store it is possible using e.g. Phonegap.

If you wish to see the plugin in action you can visit the mobile version of my web page http://www.jonasfischer.net/m.

If you are visiting my website using one of the supported operating systems (e.g. iOs or Android) then you will be prompted if you wish to view the mobile-enhanced version or the regular version: http://www.jonasfischer.net/.

Read the rest of this entry »

Allow empty selection in sfWidgetFormDoctrineChoice / Unline doctrine relations

October 12th, 2010

The standard sfWidgetFormDoctrineChoice “add_empty” option is only useful if the relation has not yet been set. However, once a relation is saved, selecting the empty value again will result in an validation error.

Here is a simple way to allow users to unlink relations by selecting the empty value of a sfWidgetFormDoctrineChoice select list. Simply add these lines to your form’s configure()-method:

$this->widgetSchema['rdr_images_list']->setOption('add_empty', true);
$valuesRaw = sfContext::getInstance()->getRequest()->getParameter($this->getName());
if (1 === count($valuesRaw['images_list']) && '' === $valuesRaw['images_list'][0]) {
  $this->validatorSchema['images_list'] = new sfValidatorPass();
}

New Symfony Helper for jQuery’s excellent form validation plugin

August 21st, 2010

I updated my old Symfony helper (see http://jnotes.jonasfischer.net/2010/03/smyfony-helper-for-jquerys-excellen-form-validation-plugin/) for the jQuery plugin “jquery.validate” (see http://docs.jquery.com/Plugins/Validation). It now supports embedded forms and is much simpler to use:

Usage

Simply insert the following code directly after the opening <form>-Tag:

< ?php $formId = 'myFormId' ?>
<form id="<?php echo $formId ?>">
< ?php
use_helper('jQueryValidator');
echo jquery_validate_form($form, $formId);
?>

This will add some css classes to the form widgets based on the validators configured in your form.

Then you can add more complex validation afterwards:

<script>
//Certificate name field is only required if a certificate is requested
$('#rdr_donation_cert_name').rules('add', {
  required: '#rdr_donation_certificate_1:checked'
});
</script>

In some cases you might want to access the jQuery-validate object itself:

<script>
 if (typeof < ?php echo $form->getName() ?>Validator !== 'undefined') {
  var donationCertificateValidator = < ?php echo $form->getName() ?>Validator; //jQuery.validate validator (instantiated in jquery_validate_form() helper)
  donationCertificateValidator.element($('#rdr_donation_cert_name'));
}
</script>

Read the rest of this entry »

Symfony Helper for jQuery’s excellent form validation plugin

March 13th, 2010

The jQuery plugin “jquery.validate” provides an easy way to implement javascript form validation with nice error messages.

I wrote this little helper method to extract the validation rules from forms defined with the symfon form framework and to automatically create the jquery.validate code to validate those forms on the client side. Of course, server side validation will still work, too.

Read the rest of this entry »

Symfony Filter: redirect depending on requesting user agent (e.g. detect mobile devices)

November 26th, 2009

I wrote two filters that allow you to configure redirect rules for requests sent from special user agents e.g. iphone, android & co.

If the requesting user agent matches the redirect rules then the redirect is issued using HTTP Headers. As a fallback for cached pages, the redirect is issued again using javascript (the filter inserts some lines of javascript code in the -section of your document).

The first one, redirectUserAgentFilter, is a generic approach to redirects depending on the user agent string. You can activate it in your filters.yml using these lines:

redirectUserAgent:
  class:  redirectUserAgentFilter
  enabled: on
  param:
    redirectUrl: http://mobile.yourdomain.com
    userAgents:
      - android
      - iphone
      - ipod

In this case, the filter would redirect all requests coming from user agents containing “android”, “iphone” oder “ipod” in their names to http://mobile.yourdomain.com.
Read the rest of this entry »

Important correction of the “More with symfony book”’s “Developing for Facebook” chapter

November 14th, 2009

I planned to use the sfFacebookConnectPlugin to pre-fill user a user profile form in one of my upcoming projects. At first I thought this would be no problem because the “More with Symfony” Book states:
“The terms of use of Facebook Connect clearly remind that one should not store any personal information about the user without the user explicitly agreeing about it, but the information provided can be used to fill forms and ask for confirmation in a click. Additionally, the website can rely on public information like name and profile picture without needing to store them.” (http://www.symfony-project.org/more-with-symfony/1_4/en/12-Developing-for-Facebook)

Unfortunately (or fortunately, because I had not invested too much time in developing the feature, yet), as a digged through the facebook api documentation, I read that this is no longer true:
“For example, we clarified that user data you get from the API is always subject to the restrictions on storage (so you shouldn’t pre-fill data in a form for users to submit to your application if you plan to store that data; users should enter that information directly)” (see http://developers.facebook.com/news.php?blog=1&story=234 or http://www.facebook.com/help/?page=431#!/help.php?page=888)

PHP’s ZipArchive Class has problems with too many (1012+) files

November 11th, 2009

ZipArchive seems to fail when adding the 1012th file.
I tested this with two different file sized and in bith cases ZipArchive::addFile() fails when adding the 1012th file. Strange.

Then I tested the same with the ZipArchiveImproved Class proposed by Farzad Ghanei (http://de.php.net/manual/de/function.ziparchive-addfile.php#88266) without problems.
I stopped testing after 5000 files without problems.

I tested this on two different machines both running PHP 5.2.6-3ubuntu4.2 with Suhosin-Patch 0.9.6.2

If you need to create a zip file and let the user stream its content while your script is still creating the archive, you should have a look at http://pablotron.org/software/zipstream-php/.
Read the rest of this entry »