Tuesday, August 6, 2013

cakephp string truncate function

String::truncate(string $text, int $length=100, array $options)
 
Parameters:
  • $text (string) – The text to truncate.
  • $length (int) – The length to trim to.
  • $options (array) – An array of options to use.
Example:
// called as TextHelper
echo $this->Text->truncate(
    'The killer crept forward and tripped on the rug.',
    22,
    array(
        'ellipsis' => '...',
        'exact' => false
    )
);

// called as String
App::uses('String', 'Utility');
echo String::truncate(
    'The killer crept forward and tripped on the rug.',
    22,
    array(
        'ellipsis' => '...',
        'exact' => false
    )
);
 
Output:
The killer crept... 

Reference url: http://book.cakephp.org/

Get Google Maps v3 to resize height of InfoWindow

Js
var infowindow = new google.maps.InfoWindow({
                                 content: lng,
                                 maxWidth: 200
                            });

google.maps.event.addListener(marker, 'click', function() {       
        var $content = $('<div class="infobox">').html("content here");
        infowindow.setContent($content.get(0));
        infowindow.open(map, marker);
});

CSS

.infobox{
    padding-bottom: 30px;
}

Have just one InfoWindow open in Google Maps API v3

google.maps.event.addListener(someMarker, 'click', function() {
   infowindow.setContent('Hello World');
   infowindow.open(map, someMarker);
});

Monday, August 5, 2013

$.browser is undefined

To keep things current, it seems that for jquery UI version 1.9, the autoHeight has been replaced by heightStyle. http://api.jqueryui.com/accordion/#option-heightStyle
  

                                              Or

just put the $.browser code in your js

var matched, browser;

jQuery.uaMatch = function( ua ) {
    ua = ua.toLowerCase();

    var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
        /(msie) ([\w.]+)/.exec( ua ) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
        [];

    return {
        browser: match[ 1 ] || "",
        version: match[ 2 ] || "0"
    };
};

matched = jQuery.uaMatch( navigator.userAgent );
browser = {};

if ( matched.browser ) {
    browser[ matched.browser ] = true;
    browser.version = matched.version;
}

// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
    browser.webkit = true;
} else if ( browser.webkit ) {
    browser.safari = true;
}

jQuery.browser = browser;

jQuery ui accordion height problem

heightStyleType: String

Default: "auto"

Controls the height of the accordion and each panel. Possible values:

    "auto": All panels will be set to the height of the tallest panel.
    "fill": Expand to the available height based on the accordion's parent height.
    "content": Each panel will be only as tall as its content.

Code examples:Initialize the accordion with the heightStyle option specified:

$( ".selector" ).accordion({ heightStyle: "content" });


Note - Use content to assign auto height to each accordion.

For this need to use jQuery 1.10 or update jQuery

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>