Skip to content

Commit

Permalink
Fixed django admin jQuery conflict issues
Browse files Browse the repository at this point in the history
  • Loading branch information
erdem committed Mar 29, 2020
1 parent 7b19cba commit cc80f2a
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ example_2/env/
assets/
tests/testapp/settings_local.py
node_modules/
/env3/
11 changes: 10 additions & 1 deletion fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
JS_FILE_MAPPING = {
"GooglePointFieldWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery_class.js",
"mapwidgets/static/mapwidgets/js/django_mw_base.js",
"mapwidgets/static/mapwidgets/js/mw_google_point_field.js",
Expand All @@ -14,12 +15,20 @@
},
"GooglePointFieldInlineWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery_class.js",
"mapwidgets/static/mapwidgets/js/django_mw_base.js",
"mapwidgets/static/mapwidgets/js/mw_google_point_field.js",
"mapwidgets/static/mapwidgets/js/mw_google_point_field_generater.js",
],
"output_file": "mapwidgets/static/mapwidgets/js/mw_google_point_inline_field.min.js"
},
"GoogleStaticOverlayMapWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery.custom.magnific-popup.js",
],
"output_file": "mapwidgets/static/mapwidgets/js/jquery.custom.magnific-popup.min.js"
}
}

Expand Down Expand Up @@ -104,7 +113,7 @@ def docker_run_unit_tests():


def docker_postgres_shell():
local('docker exec -it {} /bin/bash -c "su postgres"'.format(POSTGRES_CONTAINER_NAME))
local('docker exec -it {} /bin/bash'.format(POSTGRES_CONTAINER_NAME))


def docker_covarage_tests():
Expand Down
2 changes: 1 addition & 1 deletion mapwidgets/static/mapwidgets/js/django_mw_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@
}
});

})(jQuery || django.jQuery);
})(mapWidgets.jQuery);
Original file line number Diff line number Diff line change
Expand Up @@ -1881,4 +1881,4 @@
}
});
});
})(jQuery || django.jQuery);
})(mapWidgets.jQuery);

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion mapwidgets/static/mapwidgets/js/jquery_class.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
var mapWidgets = mapWidgets || {};
if (typeof django !== "undefined" && django.jQuery){
mapWidgets.jQuery = django.jQuery.noConflict();
}else{
mapWidgets.jQuery = jQuery.noConflict();
}


(function($) {

var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\bSuper\b/ : /.*/;
Expand Down Expand Up @@ -69,4 +77,4 @@
};
}

})(jQuery || django.jQuery);
})(mapWidgets.jQuery);
8 changes: 8 additions & 0 deletions mapwidgets/static/mapwidgets/js/jquery_init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var mapWidgets = mapWidgets || {};

// Use Django Admin jQuery function if exists, otherwise initialise `mapWidgets.jQuery` from global jQuery.
if (typeof django !== "undefined" && django.jQuery){
mapWidgets.jQuery = django.jQuery.noConflict();
}else{
mapWidgets.jQuery = jQuery.noConflict();
}
2 changes: 1 addition & 1 deletion mapwidgets/static/mapwidgets/js/mw_google_point_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
}
});

})(jQuery || django.jQuery);
})(mapWidgets.jQuery);

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
new DjangoGooglePointFieldWidget(mapWidgetOptions);
}
});
})(jQuery || django.jQuery);
})(mapWidgets.jQuery);

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
"fieldValue": fieldValue
});
{% endif %}
})(jQuery || django.jQuery);
})(mapWidgets.jQuery);
</script>
{% endblock javascript %}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@
{% block extra_javascript %}

{% endblock %}
})(jQuery || django.jQuery);
})(mapWidgets.jQuery);
</script>
{% endblock javascript %}
18 changes: 11 additions & 7 deletions mapwidgets/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def media(self):
}

js = [
"https://code.jquery.com/jquery-3.3.1.slim.min.js",
"https://maps.googleapis.com/maps/api/js?libraries=places&language={}&key={}".format(
mw_settings.LANGUAGE, mw_settings.GOOGLE_MAP_API_KEY
)
]

if not mw_settings.MINIFED: # pragma: no cover
js = js + [
"mapwidgets/js/jquery_init.js",
"mapwidgets/js/jquery_class.js",
"mapwidgets/js/django_mw_base.js",
"mapwidgets/js/mw_google_point_field.js",
Expand Down Expand Up @@ -168,14 +168,14 @@ def media(self):
}

js = [
"https://code.jquery.com/jquery-3.3.1.slim.min.js",
"https://maps.googleapis.com/maps/api/js?libraries=places&language={}&key={}".format(
mw_settings.LANGUAGE, mw_settings.GOOGLE_MAP_API_KEY
)
]

if not mw_settings.MINIFED: # pragma: no cover
js = js + [
"mapwidgets/js/jquery_init.js",
"mapwidgets/js/jquery_class.js",
"mapwidgets/js/django_mw_base.js",
"mapwidgets/js/mw_google_point_field.js",
Expand Down Expand Up @@ -289,11 +289,15 @@ class Media:
minify_if_not_debug("mapwidgets/css/magnific-popup{}.css"),
)
}

js = (
"https://code.jquery.com/jquery-3.3.1.slim.min.js",
minify_if_not_debug("mapwidgets/js/jquery.custom.magnific-popup{}.js"),
)
if not mw_settings.MINIFED: # pragma: no cover
js = (
"mapwidgets/js/jquery_init.js",
"mapwidgets/js/jquery.custom.magnific-popup.js",
)
else:
js = (
"mapwidgets/js/jquery.custom.magnific-popup.min.js",
)

def __init__(self, zoom=None, size=None, thumbnail_size=None, *args, **kwargs):
self.thumbnail_size = thumbnail_size
Expand Down

0 comments on commit cc80f2a

Please sign in to comment.