Commits

Mark Lavin committed 78e800d

Refactor JS to use data.

  • Participants
  • Parent commits fca4c43

Comments (0)

Files changed (2)

 -----------------------------------
 
 - `Django <http://www.djangoproject.com/>`_ >= 1.2
-- `jQuery <http://jquery.com/>`_ >= 1.4
+- `jQuery <http://jquery.com/>`_ >= 1.4.3
 - `jQuery UI <http://jqueryui.com/>`_ >= 1.8
 
 Optional (but recommended)

File selectable/static/js/jquery.dj.selectable.js

 	$.widget("ui.djselectable", {
         _create: function() {
             var self = $(this),
-            input = this.element,
-            type = $(input).attr('data-selectable-type');
-            
-            var allowAttr = $(input).attr('data-selectable-allow-new');
-            var allowNew = false;
-            if (typeof allowAttr !== 'undefined' && allowAttr === 'true') {
-                allowNew = true;
-            }
-
-            var multipleAttr = $(input).attr('data-selectable-multiple');
-            var allowMultiple = false;
+            input = this.element;
+            var data = $(input).data();
+            var allowNew = data['selectable-allow-new'];
+            var allowMultiple = data['selectable-multiple'];
             var deck = null;
             var textName = $(input).attr('name');
             var hiddenName = textName.replace('_0', '_1');
             var hiddenSelector = 'input[type=hidden][data-selectable-type=hidden-multiple][name=' + hiddenName + ']';
-            if (typeof multipleAttr !== 'undefined' && multipleAttr === 'true') {
-                allowMultiple = true;
+            if (allowMultiple) {
                 allowNew = false;
                 $(input).val("");
                 deck = $('<ul>').addClass('ui-widget selectable-deck');
             }
 
             function dataSource(request, response) {
-                var url = $(input).attr('data-selectable-url');
+                var url = data['selectable-url'];
                 var now = new Date().getTime();
 				$.getJSON(url, {
 					term: request.term,
                     }
                 }
             }).addClass("ui-widget ui-widget-content ui-corner-all");
-            if (type === 'combobox') {
+            if (data['selectable-type'] === 'combobox') {
                 // Change auto-complete options
                 $(input).autocomplete("option", {
                     delay: 0,