diff --git a/README.md b/README.md index 28c09ac..2441ec7 100755 --- a/README.md +++ b/README.md @@ -121,7 +121,9 @@ Screenshots Known problems ------- -Because the form type template includes javascript, there's not yet a way to bunch it all together at the very bottom of the page, so it is included at the bottom of the field. This means that jquery and the javascript plugin in Resources/public/js needs to be included before the field. I'm not sure of a way around this, but I think it's going to be addressed in a later version of the form framework. +Because the form type template includes javascript, there's not yet a standard way to bunch it all together at the very bottom of the page, so it is included at the bottom of the field. This means that jquery and the javascript plugin in Resources/public/js needs to be included before the field. + +Alternatively, you can install [LcnIncludeAssetsBundle](https://github.com/FaiblUG/LcnIncludeAssetsBundle) and then all the required scripts should get loaded in the right place and order. Credits ------- diff --git a/Resources/views/Form/google_maps.html.twig b/Resources/views/Form/google_maps.html.twig index b4df551..e78e16e 100755 --- a/Resources/views/Form/google_maps.html.twig +++ b/Resources/views/Form/google_maps.html.twig @@ -1,4 +1,5 @@ {% block oh_google_maps_widget %} +{% set scriptLoaderAvailable = lcn_include_assets_available is defined and lcn_include_assets_available %}
{% block oh_google_maps_html %}
@@ -14,43 +15,43 @@ {% endblock %} {% block oh_google_maps_javascripts %} {% if include_jquery %} - + {% if scriptLoaderAvailable %} + {{ lcn_use_javascript('//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js') }} + {% else %} + + {% endif %} {% endif %} {% if include_gmaps_js %} - + {% if scriptLoaderAvailable %} + {{ lcn_use_javascript('//maps.google.com/maps/api/js?sensor=true"') }} + {% else %} + + {% endif %} {% endif %} {% javascripts '@OhGoogleMapFormTypeBundle/Resources/public/js/jquery.ohgooglemaps.js' %} - + {% if scriptLoaderAvailable %} + {{ lcn_use_javascript(asset_url) }} + {% else %} + + {% endif %} + {% endjavascripts %} {% endblock %} {% block oh_google_maps_javascript %} {% block oh_google_maps_callback %} - {% endblock %} - + {% if scriptLoaderAvailable %} + {{ lcn_use_inline_javascript(include("OhGoogleMapFormTypeBundle:Form:inline_script.html.twig")) }} + {% else %} + + {% endif %} {% endblock %}
{% endblock %} diff --git a/Resources/views/Form/inline_script.html.twig b/Resources/views/Form/inline_script.html.twig new file mode 100644 index 0000000..33424d4 --- /dev/null +++ b/Resources/views/Form/inline_script.html.twig @@ -0,0 +1,14 @@ +$(function(){ + $('#{{ id }}_map_canvas').ohGoogleMapType({ + 'search_input_el' : $('#{{ id }}_input'), + 'search_action_el' : $('#{{ id }}_search_button'), + 'search_error_el' : $('#{{ id }}_error'), + 'current_position_el': $('#{{ id }}_current_position'), + 'default_lat' : '{% if value is defined and value and attribute(value, lat_name) %}{{ attribute(value, lat_name) }}{% else %}{{ default_lat }}{% endif %}', + 'default_lng' : '{% if value is defined and value and attribute(value, lng_name) %}{{ attribute(value, lng_name) }}{% else %}{{ default_lng }}{% endif %}', + 'default_zoom' : {% if value is defined and value and value.lat and value.lng %}15{% else %}5{% endif %}, + 'lat_field' : $('#{{ attribute(form, lat_name).vars.id }}'), + 'lng_field' : $('#{{ attribute(form, lng_name).vars.id }}'), + 'callback' : oh_google_maps_callback + }); +}); \ No newline at end of file