Commits

Mark Lavin committed 75a30e5

Simplfy including jQuery tag and make it easier to customize in the template. See #50.

  • Participants
  • Parent commits 9d4ead0

Comments (0)

Files changed (5)

 include README.rst
 include LICENSE.txt
 recursive-include selectable/static *
+recursive-include selectable/templates *

docs/quick-start.rst

 please check out the `Django documentation <https://docs.djangoproject.com/en/1.3/topics/forms/media/>`_.
 
 The jQuery and jQuery UI libraries are not included in the distribution but must be included
-in your templates. See the example project for an example using these libraries from the
-`Google CDN <http://code.google.com/apis/libraries/devguide.html#jquery>`_. Django-Selectable
-should work with `jQuery <http://jquery.com/>`_ >= 1.4.4 and `jQuery UI <http://jqueryui.com/>`_ >= 1.8
+in your templates. However there is a template tag to easily add these libraries from
+the  from the `Google CDN <http://code.google.com/apis/libraries/devguide.html#jquery>`_. 
 
-    .. literalinclude:: ../example/core/templates/base.html
-        :start-after: {% block extra-css %}{% endblock %}
-        :end-before: {% block extra-js %}
+    .. code-block:: html
+        {% load selectable_tags %}
+        {% include_jquery_libs %}
 
+By default these will use jQuery v1.7.2 and jQuery UI 1.8.18. You can customize the versions
+used by pass them to the tag. The first version is the jQuery version and the second is the
+jQuery UI version.
+
+    .. code-block:: html
+        {% load selectable_tags %}
+        {% include_jquery_libs '1.4.4' '1.8.13' %}
+
+Django-Selectable should work with `jQuery <http://jquery.com/>`_ >= 1.4.4 and 
+`jQuery UI <http://jqueryui.com/>`_ >= 1.8.13.
 
 You must also include a `jQuery UI theme <http://jqueryui.com/themeroller/>`_ stylesheet. In the
 example project we've included the "lightness" theme via the Google CDN.

example/core/templates/base.html

     {% endblock %}
     </div>
     {% include_jquery_libs %}
-    <script src="{{ STATIC_URL }}js/bootstrap.min.js"></script>
     {{ form.media.js }}
     {% block extra-js %}{% endblock %}
 </body>

selectable/templates/selectable/jquery-js.html

+{% if version %}<script src="//ajax.googleapis.com/ajax/libs/jquery/{{ version }}/jquery.min.js"></script>{% endif %}
+{% if ui %}<script src="//ajax.googleapis.com/ajax/libs/jqueryui/{{ ui }}/jquery-ui.js"></script>{% endif %}

selectable/templatetags/selectable_tags.py

 # -*- encoding: utf-8 -*-
 from django import template
-from django.template import Library
 from django.conf import settings
 
+
 register = template.Library()
 
-@register.simple_tag
-def include_jquery_libs():
-    SCRIPT_TAG = '<script type="text/javascript" src="%s"></script>'
 
-    try:
-        jquery_url = settings.JQUERY_URL
-    except:
-        jquery_url = '//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'
-
-    try:
-        jquery_ui_url = settings.JQUERY_UI_URL
-    except:
-        jquery_ui_url = '//ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js'
-
-    script_libs = SCRIPT_TAG % jquery_url
-    script_libs += '\n'
-    script_libs += SCRIPT_TAG % jquery_ui_url
-    return script_libs
-
-
+@register.inclusion_tag('selectable/jquery-js.html')
+def include_jquery_libs(version='1.7.2', ui='1.8.18'):    
+    return {'version': version, 'ui': ui}