Refactored javascript code a bit so the window event listener is only effective when the widget is shown.

This commit is contained in:
Bo Simonsen 2012-10-25 11:21:14 +02:00
parent 2f29eb70ab
commit 26aa3553ae
2 changed files with 27 additions and 11 deletions

View File

@ -10,6 +10,13 @@ Changelog
- Fixed conditional initialization of querywidget,
see https://dev.plone.org/ticket/12529 [kroman0]
- The widget can now be hidden, when clicking on the
window or the widget. The event is only effective
when the widget is displayed.
[bosim]
- Translations are now in Plone domain
[bosim]
1.0b2 (2012-03-19)
------------------

View File

@ -223,6 +223,16 @@
$.get(query, {}, function (data) { $('.QueryWidget .previewresults').html(data); });
};
/* Clicking outside a multipleSelectionWidget will close all open
multipleSelectionWidgets */
$.querywidget.hideMultiSelectionWidgetEvent = function(event) {
if ($(event.target).parents('.multipleSelectionWidget').length) {
return;
}
$('.multipleSelectionWidget dd').hide();
}
// Enhance for javascript browsers
$(document).ready(function () {
@ -274,6 +284,9 @@
$('#formfield-form-widgets-sort_on').hide();
$('#formfield-form-widgets-sort_reversed').hide();
// Bind the event that listens on the window and hide the widget
$(window).bind('click', $.querywidget.hideMultiSelectionWidgetEvent);
});
// Init widget
@ -322,20 +335,16 @@
});
$('.multipleSelectionWidget dt').live('click', function () {
$(this).parent().children('dd').toggle();
});
/* Clicking outside a multipleSelectionWidget will close all open
multipleSelectionWidgets */
$(window).click(function(event){
if ($(event.target).parents('.multipleSelectionWidget').length) {
return;
var multiselectionwidget = $(this).parent().children('dd');
if($(multiselectionwidget).is(':visible')) {
$(multiselectionwidget).hide();
$(window).unbind('click', $.querywidget.hideMultiSelectionWidgetEvent);
} else {
$(multiselectionwidget).show();
$(window).bind('click', $.querywidget.hideMultiSelectionWidgetEvent);
}
$('.multipleSelectionWidget dd').hide();
});
$('.queryindex').live('change', function () {
var fname = $(this).closest('.QueryWidget').attr('data-fieldname');
var index = $(this).find(':selected')[0].value;