Antti Kaihola avatar Antti Kaihola committed af0167c Draft

Fixed JavaScript indentation.

Comments (0)

Files changed (1)

 
 diff -r b7217d6a88f7 selectable/static/selectable/js/jquery.dj.selectable.js
 --- a/selectable/static/selectable/js/jquery.dj.selectable.js	Thu Sep 20 20:57:57 2012 -0400
-+++ b/selectable/static/selectable/js/jquery.dj.selectable.js	Tue Sep 25 11:16:35 2012 +0300
-@@ -255,9 +255,8 @@
++++ b/selectable/static/selectable/js/jquery.dj.selectable.js	Tue Sep 25 11:19:58 2012 +0300
+@@ -69,7 +69,7 @@
+ 
+         select: function(item, event) {
+             /* Trigger selection of a given item.
+-            Item should contain two properties: id and value 
++            Item should contain two properties: id and value
+             Event is the original select event if there is one.
+             Event should not be passed if trigger manually.
+             */
+@@ -145,7 +145,7 @@
+                         });
+                     }
+                     return response(results);
+-                }   
++                }
+ 				$.getJSON(url, query, unwrapResponse);
+             }
+             // Create base auto-complete lookup
+@@ -255,86 +255,87 @@
              }
          }
  	});
--})(jQuery);
++
++        window.bindSelectables = function(context) {
++            /* Bind all selectable widgets in a given context.
++            Automatically called on document.ready.
++            Additional calls can be made for dynamically added widgets.
++            */
++            $(":input[data-selectable-type=text]", context).djselectable();
++            $(":input[data-selectable-type=combobox]", context).djselectable();
++            $(":input[data-selectable-type=hidden]", context).each(function(i, elem) {
++                var hiddenName = $(elem).attr('name');
++                var textName = hiddenName.replace('_1', '_0');
++                $(":input[name=" + textName + "][data-selectable-url]").bind(
++                    "autocompletechange autocompleteselect",
++                    function(event, ui) {
++                        if (ui.item && ui.item.id) {
++                            $(elem).val(ui.item.id);
++                        } else {
++                            $(elem).val("");
++                        }
++                    }
++                );
++            });
++        };
++
++        /* Monkey-patch Django's dynamic formset, if defined */
++        if (typeof(django) !== "undefined" && typeof(django.jQuery) !== "undefined") {
++            if (django.jQuery.fn.formset) {
++                var oldformset = django.jQuery.fn.formset;
++                django.jQuery.fn.formset = function(opts) {
++                    var options = $.extend({}, opts);
++                    var addedevent = function(row) {
++                        bindSelectables($(row));
++                    };
++                    var added = null;
++                    if (options.added) {
++                        // Wrap previous added function and include call to bindSelectables
++                        var oldadded = options.added;
++                        added = function(row) { oldadded(row); addedevent(row); };
++                    }
++                    options.added = added || addedevent;
++                    return oldformset.call(this, options);
++                };
++            }
++        }
++
++        /* Monkey-patch Django's dismissAddAnotherPopup(), if defined */
++        if (typeof(dismissAddAnotherPopup) !== "undefined" && typeof(windowname_to_id) !== "undefined" && typeof(html_unescape) !== "undefined") {
++            var django_dismissAddAnotherPopup = dismissAddAnotherPopup;
++            dismissAddAnotherPopup = function(win, newId, newRepr) {
++                /* See if the popup came from a selectable field.
++                   If not, pass control to Django's code.
++                   If so, handle it. */
++                var fieldName = windowname_to_id(win.name); /* e.g. "id_fieldname" */
++                var field = $('#' + fieldName);
++                var multiField = $('#' + fieldName + '_0');
++                /* Check for bound selectable */
++                var singleWidget = field.data('djselectable');
++                var multiWidget = multiField.data('djselectable');
++                if (singleWidget || multiWidget) {
++                    // newId and newRepr are expected to have previously been escaped by
++                    // django.utils.html.escape.
++                    var item =  {
++                        id: html_unescape(newId),
++                        value: html_unescape(newRepr)
++                    };
++                    if (singleWidget) {
++                        field.djselectable('select', item);
++                    }
++                    if (multiWidget) {
++                        multiField.djselectable('select', item);
++                    }
++                    win.close();
++                } else {
++                    /* Not ours, pass on to original function. */
++                    return django_dismissAddAnotherPopup(win, newId, newRepr);
++                }
++            };
++        }
++
+ })(jQuery);
  
 -function bindSelectables(context) {
-+window.bindSelectables = function(context) {
-     /* Bind all selectable widgets in a given context.
-     Automatically called on document.ready.
-     Additional calls can be made for dynamically added widgets.
-@@ -278,7 +277,7 @@
-             }
-         );
-     });
+-    /* Bind all selectable widgets in a given context.
+-    Automatically called on document.ready.
+-    Additional calls can be made for dynamically added widgets.
+-    */
+-    $(":input[data-selectable-type=text]", context).djselectable();
+-    $(":input[data-selectable-type=combobox]", context).djselectable();
+-    $(":input[data-selectable-type=hidden]", context).each(function(i, elem) {
+-        var hiddenName = $(elem).attr('name');
+-        var textName = hiddenName.replace('_1', '_0');
+-        $(":input[name=" + textName + "][data-selectable-url]").bind(
+-            "autocompletechange autocompleteselect",
+-            function(event, ui) {
+-                if (ui.item && ui.item.id) {
+-                    $(elem).val(ui.item.id);
+-                } else {
+-                    $(elem).val("");
+-                }
+-            }
+-        );
+-    });
 -}
-+};
- 
- /* Monkey-patch Django's dynamic formset, if defined */
- if (typeof(django) !== "undefined" && typeof(django.jQuery) !== "undefined") {
-@@ -335,6 +334,8 @@
-     };
- }
- 
-+})(jQuery);
-+
+-
+-/* Monkey-patch Django's dynamic formset, if defined */
+-if (typeof(django) !== "undefined" && typeof(django.jQuery) !== "undefined") {
+-    if (django.jQuery.fn.formset) {
+-        var oldformset = django.jQuery.fn.formset;
+-        django.jQuery.fn.formset = function(opts) {
+-            var options = $.extend({}, opts);
+-            var addedevent = function(row) {
+-                bindSelectables($(row));
+-            };
+-            var added = null;
+-            if (options.added) {
+-                // Wrap previous added function and include call to bindSelectables
+-                var oldadded = options.added;
+-                added = function(row) { oldadded(row); addedevent(row); };
+-            }
+-            options.added = added || addedevent;
+-            return oldformset.call(this, options);
+-        };
+-    }
+-}
+-
+-/* Monkey-patch Django's dismissAddAnotherPopup(), if defined */
+-if (typeof(dismissAddAnotherPopup) !== "undefined" && typeof(windowname_to_id) !== "undefined" && typeof(html_unescape) !== "undefined") {
+-    var django_dismissAddAnotherPopup = dismissAddAnotherPopup;
+-    dismissAddAnotherPopup = function(win, newId, newRepr) {
+-        /* See if the popup came from a selectable field.
+-           If not, pass control to Django's code.
+-           If so, handle it. */
+-        var fieldName = windowname_to_id(win.name); /* e.g. "id_fieldname" */
+-        var field = $('#' + fieldName);
+-        var multiField = $('#' + fieldName + '_0');
+-        /* Check for bound selectable */
+-        var singleWidget = field.data('djselectable');
+-        var multiWidget = multiField.data('djselectable');
+-        if (singleWidget || multiWidget) {
+-            // newId and newRepr are expected to have previously been escaped by
+-            // django.utils.html.escape.
+-            var item =  {
+-                id: html_unescape(newId),
+-                value: html_unescape(newRepr)
+-            };
+-            if (singleWidget) {
+-                field.djselectable('select', item);
+-            }
+-            if (multiWidget) {
+-                multiField.djselectable('select', item);
+-            }
+-            win.close();
+-        } else {
+-            /* Not ours, pass on to original function. */
+-            return django_dismissAddAnotherPopup(win, newId, newRepr);
+-        }
+-    };
+-}
+-
  $(document).ready(function() {
      // Bind existing widgets on document ready
      if (typeof(djselectableAutoLoad) === "undefined" || djselectableAutoLoad) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.