浏览代码

Fix #151 - Fix event with IE8

Thomas Rabaix 13 年之前
父节点
当前提交
7163344fd3

+ 19 - 0
Resources/public/base.js

@@ -75,5 +75,24 @@ var Admin = {
             jQuery('div.sonata-ba-collapsed-fields', fieldset).toggle();
             jQuery('div.sonata-ba-collapsed-fields', fieldset).toggle();
             fieldset.toggleClass('sonata-ba-collapsed-fields-close');
             fieldset.toggleClass('sonata-ba-collapsed-fields-close');
         }).click();
         }).click();
+    },
+
+    stopEvent: function(event) {
+        // https://github.com/sonata-project/SonataAdminBundle/issues/151
+        //if it is a standard browser use preventDefault otherwise it is IE then return false
+        if(event.preventDefault) {
+            event.preventDefault();
+        } else {
+            event.returnValue = false;
+        }
+
+        //if it is a standard browser get target otherwise it is IE then adapt syntax and get target
+        if (typeof event.target != 'undefined') {
+            targetElement = event.target;
+        } else {
+            targetElement = event.srcElement;
+        }
+
+        return targetElement;
     }
     }
 }
 }

+ 11 - 9
Resources/views/CRUD/edit_orm_many_association_script.html.twig

@@ -271,11 +271,12 @@ This code manage the many-to-[one|many] association field popup
     // this function initialize the popup
     // this function initialize the popup
     // this can be only done this way has popup can be cascaded
     // this can be only done this way has popup can be cascaded
     function start_field_dialog_form_add_{{ id }}(event) {
     function start_field_dialog_form_add_{{ id }}(event) {
-        event.preventDefault();
+
+        var targetElement = Admin.stopEvent(event);
 
 
         // remove the html event a
         // remove the html event a
-        var a = jQuery(event.target).closest('a');
-        a.attr('onclick', '');
+        var a = jQuery(targetElement).closest('a');
+        a.removeAttr('onclick');
 
 
         initialize_popup_{{ id }}();
         initialize_popup_{{ id }}();
 
 
@@ -298,11 +299,11 @@ This code manage the many-to-[one|many] association field popup
         // this function initialize the popup
         // this function initialize the popup
         // this can be only done this way has popup can be cascaded
         // this can be only done this way has popup can be cascaded
         function start_field_dialog_form_list_{{ id }}(event) {
         function start_field_dialog_form_list_{{ id }}(event) {
-            event.preventDefault();
+            var targetElement = Admin.stopEvent(event);
 
 
             // remove the html event a
             // remove the html event a
-            var a = jQuery(event.target).closest('a');
-            a.attr('onclick', '');
+            var a = jQuery(targetElement).closest('a');
+            a.removeAttr('onclick');
 
 
             initialize_popup_{{ id }}();
             initialize_popup_{{ id }}();
 
 
@@ -316,10 +317,11 @@ This code manage the many-to-[one|many] association field popup
         }
         }
 
 
         function remove_selected_element_{{ id }}(event) {
         function remove_selected_element_{{ id }}(event) {
-            event.preventDefault();
+            var targetElement = Admin.stopEvent(event);
 
 
-            var a = jQuery(event.target).closest('a');
-            a.attr('onclick', '');
+            // remove the html event a
+            var a = jQuery(targetElement).closest('a');
+            a.removeAttr('onclick');
 
 
             a.click(field_remove_element_{{ id}});
             a.click(field_remove_element_{{ id}});
 
 

+ 3 - 3
Resources/views/CRUD/edit_orm_one_association_script.html.twig

@@ -55,11 +55,11 @@ This code manage the one-to-many association field popup
     // this function initialize the popup
     // this function initialize the popup
     // this can be only done this way has popup can be cascaded
     // this can be only done this way has popup can be cascaded
     function start_field_retrieve_{{ id }}(event) {
     function start_field_retrieve_{{ id }}(event) {
-        event.preventDefault();
+        var targetElement = Admin.stopEvent(event);
 
 
         // remove the html event a
         // remove the html event a
-        var a = jQuery(event.target).closest('a');
-        a.attr('onclick', '');
+        var a = jQuery(targetElement).closest('a');
+        a.removeAttr('onclick');
 
 
         // initialize component
         // initialize component
         field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
         field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");