in_array() in eZ Publish Templates

eZ Publish templates do not offer the standard ‘in_array’ function found in php, you can however achieve this with the eZ tpl ‘switch’ function:

{switch match=$digit}
   {case in=array( 1, 2 )}
       This one matches.
    {/case}
   {case in=array( 2, 3 )}
      This one does not match.
   {/case}
   {case}
      Not this one either.
   {/case}
{/switch}

Fancybox close


If you absolutely must use Fancybox then remember…

Fancybox (http://fancybox.net/)

If you have opened fancybox in an iFrame you may notice that the out of the box close function doesn’t work…

$.fancybox.close();

This is because you need to run the function from the parent, ie the top window. To achieve this, simply prepend the above with ‘parent’:

parent.$.fancybox.close();

jQueryUI Date Picker Class

The jQuery UI Date picker is a pretty complete package and generally does what it says on the tin… but not always. As soon as you start to have multiple date ranges on one screen things can start to get a little messy with the default functionality of the jQuery API. However this confusion is easily removed when you remember that each date picker input can be modified with a simple javascript date object.
I was recently tasked with creating a page with an unknown number of date pickers, both single dates and date ranges. After searching for what other people had done to tackle this problem nothing immediately came to my finger tips, but as usual all the components were there and this is what I came up with:
The Brief:
1 – One class to handle all date pickers on entire site
2 – Control class from html (used inside of eZ Publish framework, template caches are easier to clear than script caches)
3 – Class to handle:
   1 – single date pickers
   2 – date picker ranges
   3 – date picker ranges limited by each other and limited by over all min and max.

THE JS

myworks.date_picker = {
init: function(){
$(document).ready(function(){

$.datepicker.setDefaults( $.datepicker.regional[ $(‘.jquery_date_format’).first().attr(‘lng’) ] );

/*Loop through all datepickers with the ranges attribute and add counters*/
$(‘.jquery_date_picker[picker-type=”range”]’).each(function(index){
$(this).attr(‘count’,index);
});

/* OPTIONAL OPERATORS TO SEND VIA HTML ATTRIBUTES

1 – picker-type = ‘range’ || ‘single’. Default is single. 

2 – rangeSpan = numeric numer of days the range can accept. Default is 30days.

3 – max = the jquery ui default max limits, eg -2d. This will be overriden if rangeSpan exists. Default is 24M.

4 – default = this will be the datepickers start chosen date, units in either date object or jquery ui days or months eg -2d */

$(‘.jquery_date_picker’).datepicker({
beforeShow: myworks.date_picker.customRange,
changeMonth: true,
numberOfMonths: 1
});
});
},
date_object_create: function(inputValue){
var date_parts = inputValue.split(‘/’),
/*trim_leading_zeros uses parseInt and a little regex to trim 08 to 8*/
year = myworks.toolbox.trim_leading_zeros( date_parts[2] ),
month = myworks.toolbox.trim_leading_zeros(date_parts[1]) – 1,
day = myworks.toolbox.trim_leading_zeros(date_parts[0]);
return new Date(year,  month, day);
},
customRange: function(){
var lng = $(this).attr(‘lng’),
defaultDateObject = $(this).attr(‘default’) || null,
type = $(this).attr(‘picker-type’) || ‘single’;
$.datepicker.setDefaults( $.datepicker.regional[ lng ] );
/*if not range return nothing*/
if(type != ‘range’){
return;
/*else determine the min/max dates available for this datepickeer based on attributes on html element*/
}else{
var min = new Date(2011, 11 – 1, 1),
max = $(this).attr(‘max’) || ’24M’;
/*even counts are 1st rnage partners*/

var origin_count = $(this).attr(‘count’);
if( origin_count%2 == 0){
var partner_count = parseInt(origin_count) + 1,
range_partner = ‘.jquery_date_picker[count=’+partner_count+’]’;
/*if the end date has content, do not allow the start date to be after it*/

if( $(”+range_partner+”).val() != ”){
/*get the date, split and return js date object*/
var val = $(”+range_partner+”).val(),
end_date = sawdays.date_picker.date_object_create(val);
/*resetting the max date according to the maxDate input field*/
max = end_date;
}
}else{
var partner_count = parseInt(origin_count) – 1,
range_partner = ‘.jquery_date_picker[count=’+partner_count+’]’;
/*if the start date has content, do not allow the end date to start before it*/

if( $(”+range_partner+”).val() != ”){
/*get the date, split and return js date object*/

var val = $(”+range_partner+”).val(),
start_date = sawdays.date_picker.date_object_create(val);
/*resetting the min date based on the mindate input field*/

min = start_date;
}
}
/*start/end date difference limitted*/ if($(this).attr(‘rangeSpan’)){
var rangeInDays = parseInt($(this).attr(‘rangeSpan’)) || 30;
/*startdate input cals*/

if( origin_count%2 == 0){
/*The start date cannot be sooner than the end minus the rangeInDays */

if( $(”+range_partner+”).val() != null){
if( $(”+range_partner+”).val() != ”){
var val = $(”+range_partner+”).val(),
end_date = myworks.date_picker.date_object_create(val),
min_determined = new Date(end_date.getFullYear(), end_date.getMonth(), end_date.getDate() – rangeInDays),
max = end_date;
if (min_determined > min){
min = min_determined;
}
}
}
}else{
/*caculating min and max based on rangeSpan attribute*/

if( $(”+range_partner+”).val() != null){
if( $(”+range_partner+”).val() != ”){
var val = $(”+range_partner+”).val(),
start_date = myworks.date_picker.date_object_create(val),
min = start_date,
max = new Date(start_date.getFullYear(), start_date.getMonth(), start_date.getDate() + rangeInDays);
}
}
}
}
/*return the min and max dates to the datepicker*/

return {
defaultDate: defaultDateObject,
minDate: min,
maxDate: max
}
}
}
}
myworks.date_picker.init();

THE HTML

From:

to:

From:

to: