| 1 |
/* |
| 2 |
* Google Maps Widget |
| 3 |
* (c) Web factory Ltd, 2012 - 2013 |
| 4 |
*/ |
| 5 |
|
| 6 |
jQuery(function($) { |
| 7 |
$('.gmw-tabs').each(function(i, el) { |
| 8 |
change_pin_type(el); |
| 9 |
change_link_type(el); |
| 10 |
$('.gmw_thumb_pin_type', el).on('change', function() { change_pin_type(el) }); |
| 11 |
$('.gmw_thumb_link_type', el).on('change', function() { change_link_type(el) }); |
| 12 |
el_id = $(el).attr('id'); |
| 13 |
$(el).tabs({ active: get_active_tab(el_id), |
| 14 |
activate: function(event, ui) { save_active_tab(this); } |
| 15 |
}); |
| 16 |
}); |
| 17 |
|
| 18 |
// get active tab index from cookie |
| 19 |
function get_active_tab(el_id) { |
| 20 |
id = parseInt(0 + $.cookie(el_id), 10); |
| 21 |
|
| 22 |
return id; |
| 23 |
} // get_active_tab |
| 24 |
|
| 25 |
// save active tab index to cookie |
| 26 |
function save_active_tab(elem) { |
| 27 |
$.cookie($(elem).attr('id'), $(elem).tabs('option', 'active'), { expires: 30 }); |
| 28 |
} // save_active_tab |
| 29 |
|
| 30 |
// show/hide custom link field based on user's link type choice |
| 31 |
function change_link_type(widget) { |
| 32 |
if ($('.gmw_thumb_link_type', widget).val() == 'custom') { |
| 33 |
$('.gmw_thumb_link_section', widget).show(); |
| 34 |
} else { |
| 35 |
$('.gmw_thumb_link_section', widget).hide(); |
| 36 |
} |
| 37 |
} // link_type |
| 38 |
|
| 39 |
// show/hide custom pin URL field based on user's pin type choice |
| 40 |
function change_pin_type(widget) { |
| 41 |
if ($('.gmw_thumb_pin_type', widget).val() == 'custom') { |
| 42 |
$('.gmw_thumb_pin_type_custom_section', widget).show(); |
| 43 |
$('.gmw_thumb_pin_type_predefined_section', widget).hide(); |
| 44 |
} else { |
| 45 |
$('.gmw_thumb_pin_type_custom_section', widget).hide(); |
| 46 |
$('.gmw_thumb_pin_type_predefined_section', widget).show(); |
| 47 |
} |
| 48 |
} // pin_type |
| 49 |
|
| 50 |
// re-tab on GUI rebuild |
| 51 |
$('div[id*="googlemapswidget"]').ajaxSuccess(function(event, request, option) { |
| 52 |
$('.gmw-tabs').each(function(i, el) { |
| 53 |
change_pin_type(el); |
| 54 |
change_link_type(el); |
| 55 |
$('.gmw_thumb_pin_type', el).on('change', function() { change_pin_type(el) }); |
| 56 |
$('.gmw_thumb_link_type', el).on('change', function() { change_link_type(el) }); |
| 57 |
el_id = $(el).attr('id'); |
| 58 |
$(el).tabs({ active: get_active_tab(el_id), |
| 59 |
activate: function(event, ui) { save_active_tab(this); } |
| 60 |
}); |
| 61 |
}); |
| 62 |
}); |
| 63 |
}); // onload |