Archive for the ‘Web development’ Category

You can stop nested elements triggering their parent element event handlers (DOM bubbling) using this handy jQuery method:
http://api.jquery.com/event.stopImmediatePropagation/
I ran into this issue whilst working on a calendar/scheduling app. Where day containing elements needed click events and their child elements needed click events too.
Love the jQuery ;]

I was experiencing this issue with some larger file uploads using the CakePHP Media plugin.
https://bugs.webkit.org/show_bug.cgi?id=5760
Add this to the virtual host declaration in your Apache config file to fix it:
123456<VirtualHost x.x.x.x:x>

    # Prevent Safari from hanging on uploads
    BrowserMatch  Safari  nokeepalive

</VirtualHost>

Especially if you’re trying to match attributes and their values!
Thankfully Kooilnc, the godsend has a solution:
http://stackoverflow.com/questions/1231770/innerhtml-removes-attribute-quotes-in-internet-explorer
I’ve wrapped that up into a jQuery function here:
123456789101112131415161718192021222324$.fn.ieInnerHTML = function() {
  var zz = this.html(),
       z =
     zz.match(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|’.*?’|[^'">\s]+))?)+\s*|\s*)\/?>/g);
    if (z){
      for (var i=0;i<z.length;i++){
        var y, zSaved = z[i];
  [...]

God I hate IE…. and I really don’t often hate anything….
IE tends to cache its responses to some AJAX requests, which if you ask me is very stupid for its default behaviour.
FireFox caching is disabled by default. As always much love to the Fox.
Anyway, if you’re using jQuery.ajax() remember to pass the cache: false argument [...]

For my own records but may also be of interest to some…
This statement performs 4 conditional left outer joins and then uses CASE to conditionally select the returned columns as a single group of columns.
So a polymorphic one to one relationship is returned in a single query.
123456789101112131415$sql = <<<SQL
SELECT *, ELT(Log.action,’$elt_list’) AS what,
 CASE WHEN [...]

If you’re trying to use the CakePHP Media plugin with 1.3 (I’m running RC3) and you get this error when deleting an attachment:
1Call to undefined method Folder::ls() in /path_to_app/app/plugins/media/models/behaviors/media.php  on line 277
ls() has been deprecated in favour of read(), change line 277 of /path_to_app/app/plugins/media/models/behaviors/media.php to:
1list($versions, ) = $Folder->read();
All should work fine thereafter ;]

I wasn’t having much luck with the example given in the CakePHP book for a Has and Belongs To Many relationship with a single option select menu in the view.
Anyway overriding the element type does the trick:
1<?php echo $form->input(’ResellerField’, array(’multiple’ => false)) ?>

To create a helper which name consists of more than one word use the following naming convention:
12345678910111213# Helper name: MyHelper

# File name
app/views/helpers/my_helper.php

# Class name (Camel Case)
class MyHelper extends AppHelper

# In Controller (Camel Case)
var $helpers = array(’MyHelper’);

# In View (Camel Back):
$myHelper->method();

I had the issue where my MacBook creates files prefixed with ._ while working on a Samba share. I’ve fixed this once before but it was so long ago, I’ve forgotten how!! Anyway, I had a stack of these files in a checked-out svn project and needed to delete them. Rather than do each one [...]

This is quite handy if you’re working in a team and you don’t want the designer/client poking about in the controllers to set page titles. You can set them in the view using this code:
1<? $this->pageTitle = ‘My page title’ ?>


top