From 61000dc074a5d90dfae3c21ac234400c7baf4ea8 Mon Sep 17 00:00:00 2001
From: dropfen <boris.kotov@gmail.com>
Date: Sun, 11 Jan 2015 23:25:04 +0100
Subject: [PATCH 01/33] Call attr() instead of prop() to set it to selected

Had this issue in Chrome & Meteor, that I couldn't  set an option to selected. This Fix helped.
---
 jquery.dropdown.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index c37007f..1bac736 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -305,7 +305,7 @@
 
       // Ss it selected?
       if ($this.prop("selected")) {
-        $option.prop("selected", true);
+        $option.attr("selected", true);
       }
 
       // Append option to our dropdown

From 663d3c2169d84e98fd371f8e4b706387f340bcdc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jesu=CC=81s=20Pe=CC=81rez?= <jesusprubio@gmail.com>
Date: Tue, 3 Mar 2015 10:24:12 +0100
Subject: [PATCH 02/33] UDM support added (CommonJS/Browserify included)

---
 README.md          | 16 ++++++++++++++++
 jquery.dropdown.js | 15 +++++++++++++--
 package.json       | 24 ++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 package.json

diff --git a/README.md b/README.md
index 7ac6f59..f8c46ef 100644
--- a/README.md
+++ b/README.md
@@ -59,3 +59,19 @@ You may add a new option to the select tag and it will be automatically added to
 ### Let users add options
 
 Add `data-dynamic-opts=true` to the select tag to let users add or remove options.
+
+### Browserify
+
+This library is [UMD](https://github.com/umdjs/umd) compatible, so you can use it in this way:
+
+```javascript
+var jquery = require("jquery");
+require("dropdown.js");
+
+jquery.material.init();
+
+jquery(document).ready(function() {
+    $(".select").dropdown({"optionClass": "withripple"});
+});
+...
+```
diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 1bac736..f80ef1d 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -1,6 +1,17 @@
 /* globals jQuery, window, document */
 
-(function($) {
+(function (factory) {
+    if (typeof define === 'function' && define.amd) {
+        // AMD. Register as an anonymous module.
+        define(['jquery'], factory);
+    } else if (typeof exports === 'object') {
+        // Node/CommonJS
+        module.exports = factory(require('jquery'));
+    } else {
+        // Browser globals
+        factory(jQuery);
+    }
+}(function($) {
 
   var methods = {
     options : {
@@ -327,4 +338,4 @@
     }
   };
 
-})(jQuery);
+}));
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ca1c4a4
--- /dev/null
+++ b/package.json
@@ -0,0 +1,24 @@
+{
+  "name": "dropdown.js",
+  "version": "0.0.2dev",
+  "description": "Finally a dropdown plugin that transforms select inputs in nice dropdowns and does not drive you crazy.",
+  "main": "jquery.dropdown",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/FezVrasta/dropdown.js.git"
+  },
+  "keywords": [
+    "dropdown",
+    "dropdown.js",
+    "choosen",
+    "selectize",
+    "select",
+    "multiselect"
+  ],
+  "author": "FezVrasta",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/FezVrasta/dropdown.js/issues"
+  },
+  "homepage": "https://github.com/FezVrasta/dropdown.js"
+}

From dcd58f11b9f84cefa682e5627a15f906313d83fa Mon Sep 17 00:00:00 2001
From: Arun Poudel <arunpoudel@users.noreply.github.com>
Date: Wed, 22 Apr 2015 12:02:02 +0200
Subject: [PATCH 03/33] Fixes ":selected" attribute not being honoured

selected attribute of the option wasn't being honoured because the selector passed was wrong.
---
 jquery.dropdown.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index f80ef1d..9c6a5fb 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -88,15 +88,15 @@
         // If is a single select, selected the first one or the last with selected attribute
         if (!multi) {
           var $selected;
-          if ($ul.find("[selected]").length) {
-            $selected = $ul.find("[selected]").last();
+          if ($ul.find(":selected").length) {
+            $selected = $ul.find(":selected").last();
           }
           else {
             $selected = $ul.find("li").first();
           }
           methods._select($dropdown, $selected);
         } else {
-          methods._select($dropdown, $ul.find("[selected]"));
+          methods._select($dropdown, $ul.find(":selected"));
         }
 
         // Transfer the classes of the select to the input dropdown

From a540c629178b4c9bfcc298cfac3bd75aa8b6b3d9 Mon Sep 17 00:00:00 2001
From: Nicholas Ventimiglia <nick@avariceonline.com>
Date: Thu, 4 Jun 2015 13:23:14 -0700
Subject: [PATCH 04/33] Update jquery.dropdown.js

Fix for <select> elements
---
 jquery.dropdown.js | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 9c6a5fb..f104d6e 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -87,16 +87,17 @@
 
         // If is a single select, selected the first one or the last with selected attribute
         if (!multi) {
-          var $selected;
-          if ($ul.find(":selected").length) {
-            $selected = $ul.find(":selected").last();
-          }
-          else {
-            $selected = $ul.find("li").first();
-          }
-          methods._select($dropdown, $selected);
+            var $selected;
+            if ($select.find(":selected").length) {
+                $selected = $select.find(":selected").last();
+            }
+            else {
+                $selected = $select.find("option, li").first();
+               // $selected = $select.find("option").first();
+            }
+            methods._select($dropdown, $selected);
         } else {
-          methods._select($dropdown, $ul.find(":selected"));
+            methods._select($dropdown, $select.find(":selected"));
         }
 
         // Transfer the classes of the select to the input dropdown

From e2e83f7b10687f8af7526fd358078c146dfde1df Mon Sep 17 00:00:00 2001
From: Nicholas Ventimiglia <nick@avariceonline.com>
Date: Sun, 7 Jun 2015 09:17:38 -0700
Subject: [PATCH 05/33] onSelected event handler

onSelected event handler
---
 jquery.dropdown.js | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index f104d6e..ad3167c 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -19,6 +19,7 @@
       "dropdownClass": "",
       "autoinit": false,
       "callback": false,
+      "onSelected": false,
       "dynamicOptLabel": "Add a new option..."
     },
     init: function(options) {
@@ -286,6 +287,11 @@
           $select.addClass("empty");
         }
       }
+      
+       // Call the callback
+        if (this.options.onSelected) {
+            this.options.onSelected($target.attr("value"));
+        }
 
     },
     _addOption: function($ul, $this) {

From 0b13f808d754be1824d833b9e227b7d35292fedc Mon Sep 17 00:00:00 2001
From: Lukas Liesis <liesislukas@gmail.com>
Date: Sat, 20 Jun 2015 15:05:26 +0300
Subject: [PATCH 06/33] Update jquery.dropdown.js

trim'ing blankspace coming from html
---
 jquery.dropdown.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 9c6a5fb..85a6694 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -274,7 +274,7 @@
         // Set the value to the native select
         $select.val($target.attr("value"));
         // Set the value to the input
-        $input.val($target.text());
+        $input.val($target.text().trim());
       }
 
       // This is used only if Material Design for Bootstrap is selected

From 650c4cf671a186b36a6fa8e608b8812d15aaea0e Mon Sep 17 00:00:00 2001
From: Alexander Pilipenko <hamper.nhs@gmail.com>
Date: Tue, 21 Jul 2015 20:11:30 +0300
Subject: [PATCH 07/33] autoinit nested selects

---
 jquery.dropdown.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index c18d59f..2b4b58a 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -218,7 +218,10 @@
       if (options.autoinit) {
         $(document).on("DOMNodeInserted", function(e) {
           var $this = $(e.target);
-          if ($this.is("select") && $this.is(options.autoinit)) {
+          if (!$this.is("select")) {
+            $this = $this.find('select');
+          }
+          if ($this.is(options.autoinit)) {
             initElement($this);
           }
         });

From 5cfb2b1f8024035c5339c46192f93fdf428ac670 Mon Sep 17 00:00:00 2001
From: Alexander Pilipenko <hamper.nhs@gmail.com>
Date: Tue, 21 Jul 2015 22:27:00 +0300
Subject: [PATCH 08/33] fix multi selects init

---
 jquery.dropdown.js | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 2b4b58a..56a814a 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -98,7 +98,13 @@
             }
             methods._select($dropdown, $selected);
         } else {
-            methods._select($dropdown, $select.find(":selected"));
+            var selectors = [], val = $select.val()
+            for (var i in val) {
+              selectors.push('li[value=' + val[i] + ']')
+            }
+            if (selectors.length > 0) {
+              methods._select($dropdown, $dropdown.find(selectors.join(',')));
+            }
         }
 
         // Transfer the classes of the select to the input dropdown
@@ -242,7 +248,6 @@
       // Get dropdown's elements
       var $select = $dropdown.data("select"),
           $input  = $dropdown.find("input.fakeinput");
-
       // Is it a multi select?
       var multi = $select.attr("multiple");
 
@@ -254,12 +259,10 @@
         // Toggle option state
         $target.toggleClass("selected");
         // Toggle selection of the clicked option in native select
-        var $selected = $select.find("[value=\"" + $target.attr("value") + "\"]");
-        if ($selected.prop("selected")) {
-          $selected.prop("selected", true);
-        } else {
-          $selected.prop("selected", false);
-        }
+        $target.each(function(){
+          var $selected = $select.find("[value=\"" + $(this).attr("value") + "\"]");
+          $selected.prop("selected", $target.prop("selected"));
+        })
         // Add or remove the value from the input
         var text = [];
         selectOptions.each(function() {

From 8e7e69b16604dad527fb8368c29666d73430cc18 Mon Sep 17 00:00:00 2001
From: Alexander Pilipenko <hamper.nhs@gmail.com>
Date: Wed, 22 Jul 2015 20:19:43 +0300
Subject: [PATCH 09/33] fix

---
 jquery.dropdown.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 56a814a..508b16d 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -261,7 +261,7 @@
         // Toggle selection of the clicked option in native select
         $target.each(function(){
           var $selected = $select.find("[value=\"" + $(this).attr("value") + "\"]");
-          $selected.prop("selected", $target.prop("selected"));
+          $selected.prop("selected", $(this).hasClass("selected"));
         })
         // Add or remove the value from the input
         var text = [];

From 23613f9615653e9d9b49031d80952e1b0be0a704 Mon Sep 17 00:00:00 2001
From: Fez Vrasta <fez@tekhy.net>
Date: Tue, 4 Aug 2015 13:56:39 +0200
Subject: [PATCH 10/33] autoprefixed

---
 jquery.dropdown.css | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/jquery.dropdown.css b/jquery.dropdown.css
index 33ccba8..ee3903d 100644
--- a/jquery.dropdown.css
+++ b/jquery.dropdown.css
@@ -10,23 +10,31 @@
   text-overflow: ellipsis;
 }
 .dropdownjs > input.focus ~ ul {
-  transform: scale(1);
+  -webkit-transform: scale(1);
+      -ms-transform: scale(1);
+          transform: scale(1);
 }
 .dropdownjs > ul {
   position: absolute;
   padding: 0;
   margin: 0;
   min-width: 200px;
-  transform: scale(0);
+  -webkit-transform: scale(0);
+      -ms-transform: scale(0);
+          transform: scale(0);
   z-index: 10000;
 }
 .dropdownjs > ul[placement=top-left] {
-  transform-origin: bottom left;
+  -webkit-transform-origin: bottom left;
+      -ms-transform-origin: bottom left;
+          transform-origin: bottom left;
   bottom: 0;
   left: 0;
 }
 .dropdownjs > ul[placement=bottom-left] {
-  transform-origin: top left;
+  -webkit-transform-origin: top left;
+      -ms-transform-origin: top left;
+          transform-origin: top left;
   top: 0;
   left: 0;
 }
@@ -53,7 +61,8 @@ select[data-dropdownjs][disabled] + .dropdownjs > input[readonly] {
 .dropdownjs > ul {
   background: #FFF;
   box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12), 0 1px 6px rgba(0, 0, 0, 0.12);
-  transition: transform 0.2s ease-out;
+  -webkit-transition: -webkit-transform 0.2s ease-out;
+          transition: transform 0.2s ease-out;
   padding: 10px;
   overflow: auto;
   max-width: 500px;

From fbfeed591899f919d6ac47bc41693c42738c2c03 Mon Sep 17 00:00:00 2001
From: Nectarios <contact@nekkon.com>
Date: Wed, 5 Aug 2015 00:09:56 +0300
Subject: [PATCH 11/33] .val+change fix

.val("value").trigger("change"); works with this change
---
 jquery.dropdown.js | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 508b16d..08da9b4 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -173,6 +173,25 @@
           $ul.find("li").not(".dropdownjs-add").attr("tabindex", 0);
 
         });
+        
+        // Update dropdown when using val, need to use .val("value").trigger("change");
+        $select.on("change", function(e) {
+          var $this = $(e.target);
+          if (!$this.val().length) return;
+
+          if (!multi) {
+            var $selected;
+            if ($select.find(":selected").length) {
+              $selected = $select.find(":selected").last();
+            }
+            else {
+              $selected = $select.find("option, li").first();
+            }
+            methods._select($dropdown, $selected);
+          } else {
+            methods._select($dropdown, $select.find(":selected"));
+          }
+        });
 
         // Used to make the dropdown menu more dropdown-ish
         $input.on("click focus", function(e) {

From dec4fba1aa62969b4f0cae4feb3031364a3712f0 Mon Sep 17 00:00:00 2001
From: Ariel Bottero <ab@abcontenidos.com>
Date: Fri, 30 Oct 2015 22:20:36 -0300
Subject: [PATCH 12/33] jquery.dropdown.js

Highlighted the current selection

if($target[0].tagName.toUpperCase()=="LI") {selectOptions.not($target).removeClass("selected"); } // at line 298
$option.addClass("selected"); // at line 351
---
 jquery.dropdown.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 08da9b4..77e3d38 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -295,7 +295,7 @@
       // Behavior for single select
       if (!multi) {
         // Unselect options except the one that will be selected
-        selectOptions.not($target).removeClass("selected");
+        if($target[0].tagName.toUpperCase()=="LI") {selectOptions.not($target).removeClass("selected"); }
         // Select the selected option
         $target.addClass("selected");
         // Set the value to the native select
@@ -349,6 +349,7 @@
       // Ss it selected?
       if ($this.prop("selected")) {
         $option.attr("selected", true);
+		$option.addClass("selected");
       }
 
       // Append option to our dropdown

From a08df5ccb7bdb50e1c8c3eb84a3f7a966f33d533 Mon Sep 17 00:00:00 2001
From: Ariel Bottero <ab@abcontenidos.com>
Date: Mon, 2 Nov 2015 11:18:11 -0300
Subject: [PATCH 13/33] Update jquery.dropdown.js

---
 jquery.dropdown.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 77e3d38..2f81c5f 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -295,7 +295,9 @@
       // Behavior for single select
       if (!multi) {
         // Unselect options except the one that will be selected
-        if($target[0].tagName.toUpperCase()=="LI") {selectOptions.not($target).removeClass("selected"); }
+        if ($target.is("li")) {
+            selectOptions.not($target).removeClass("selected");
+        }
         // Select the selected option
         $target.addClass("selected");
         // Set the value to the native select
@@ -349,7 +351,7 @@
       // Ss it selected?
       if ($this.prop("selected")) {
         $option.attr("selected", true);
-		$option.addClass("selected");
+        $option.addClass("selected");
       }
 
       // Append option to our dropdown

From b81ef15c7088fde384a4324b0161160198df51dc Mon Sep 17 00:00:00 2001
From: Daniele <daniele.ferro@crmvillage.biz>
Date: Fri, 13 Nov 2015 09:03:55 +0100
Subject: [PATCH 14/33] Update jquery.dropdown.js

---
 jquery.dropdown.js | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 08da9b4..f12cf6c 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -247,7 +247,9 @@
             $this = $this.find('select');
           }
           if ($this.is(options.autoinit)) {
-            initElement($this);
+            $this.each(function() {
+              initElement($(this));
+            });
           }
         });
       }

From b43d06e29f40d7e23597e3f8823a638fd596c453 Mon Sep 17 00:00:00 2001
From: Chris Trinh <ChrisT11@verifone.com>
Date: Wed, 11 May 2016 11:28:36 -0700
Subject: [PATCH 15/33] dropdown class and option class apply the correct
 styles

---
 jquery.dropdown.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index b24a789..d3fd63d 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -46,7 +46,7 @@
 
         // Create the dropdown wrapper
         var $dropdown = $("<div></div>");
-        $dropdown.addClass("dropdownjs").addClass(options.dropdownStyle);
+        $dropdown.addClass("dropdownjs").addClass(options.dropdownClass);
         $dropdown.data("select", $select);
 
         // Create the fake input used as "select" element and cache it as $input
@@ -173,7 +173,7 @@
           $ul.find("li").not(".dropdownjs-add").attr("tabindex", 0);
 
         });
-        
+
         // Update dropdown when using val, need to use .val("value").trigger("change");
         $select.on("change", function(e) {
           var $this = $(e.target);
@@ -316,7 +316,7 @@
           $select.addClass("empty");
         }
       }
-      
+
        // Call the callback
         if (this.options.onSelected) {
             this.options.onSelected($target.attr("value"));
@@ -328,7 +328,7 @@
       var $option = $("<li></li>");
 
       // Style the option
-      $option.addClass(this.options.optionStyle);
+      $option.addClass(this.options.optionClass);
 
       // If the option has some text then transfer it
       if ($this.text()) {

From b227a5e2b4327547f7c9abe0c1d7fcf402dc7b43 Mon Sep 17 00:00:00 2001
From: Chris Trinh <ChrisT11@verifone.com>
Date: Thu, 12 May 2016 13:38:36 -0700
Subject: [PATCH 16/33] Fix bug causing onselected to be fired twice and fix
 formmatting

---
 jquery.dropdown.js | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index d3fd63d..8f1327d 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -80,9 +80,6 @@
           $dynamicInput.find("input").attr("placeholder", options.dynamicOptLabel);
           $ul.append($dynamicInput);
         }
-
-
-
         // Cache the dropdown options
         var selectOptions = $dropdown.find("li");
 
@@ -91,11 +88,10 @@
             var $selected;
             if ($select.find(":selected").length) {
                 $selected = $select.find(":selected").last();
-            }
-            else {
+            } else {
                 $selected = $select.find("option, li").first();
-               // $selected = $select.find("option").first();
             }
+
             methods._select($dropdown, $selected);
         } else {
             var selectors = [], val = $select.val()
@@ -128,8 +124,6 @@
         // On click, set the clicked one as selected
         $ul.on("click", "li:not(.dropdownjs-add)", function(e) {
           methods._select($dropdown, $(this));
-          // trigger change event, if declared on the original selector
-          $select.change();
         });
         $ul.on("keydown", "li:not(.dropdownjs-add)", function(e) {
           if (e.which === 27) {
@@ -141,7 +135,6 @@
             return false;
           }
         });
-
         $ul.on("focus", "li:not(.dropdownjs-add)", function() {
           if ($select.is(":disabled")) {
             return;
@@ -183,8 +176,7 @@
             var $selected;
             if ($select.find(":selected").length) {
               $selected = $select.find(":selected").last();
-            }
-            else {
+            } else {
               $selected = $select.find("option, li").first();
             }
             methods._select($dropdown, $selected);
@@ -261,6 +253,7 @@
     },
     select: function(target) {
       var $target = $(this).find("[value=\"" + target + "\"]");
+      console.log("called from select");
       methods._select($(this), $target);
     },
     _select: function($dropdown, $target) {
@@ -280,10 +273,10 @@
         // Toggle option state
         $target.toggleClass("selected");
         // Toggle selection of the clicked option in native select
-        $target.each(function(){
+        $target.each(function() {
           var $selected = $select.find("[value=\"" + $(this).attr("value") + "\"]");
           $selected.prop("selected", $(this).hasClass("selected"));
-        })
+        });
         // Add or remove the value from the input
         var text = [];
         selectOptions.each(function() {
@@ -298,7 +291,7 @@
       if (!multi) {
         // Unselect options except the one that will be selected
         if ($target.is("li")) {
-            selectOptions.not($target).removeClass("selected");
+          selectOptions.not($target).removeClass("selected");
         }
         // Select the selected option
         $target.addClass("selected");
@@ -317,11 +310,10 @@
         }
       }
 
-       // Call the callback
-        if (this.options.onSelected) {
-            this.options.onSelected($target.attr("value"));
-        }
-
+      // Call the callback
+      if (this.options.onSelected) {
+        this.options.onSelected($target.attr("value"));
+      }
     },
     _addOption: function($ul, $this) {
       // Create the option

From aa6af20a9a9631452acf1d30886bb9d6c78fe51a Mon Sep 17 00:00:00 2001
From: Chris Trinh <ChrisT11@verifone.com>
Date: Thu, 12 May 2016 13:45:43 -0700
Subject: [PATCH 17/33] Remove console logging

---
 jquery.dropdown.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 8f1327d..29c4bfe 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -253,7 +253,6 @@
     },
     select: function(target) {
       var $target = $(this).find("[value=\"" + target + "\"]");
-      console.log("called from select");
       methods._select($(this), $target);
     },
     _select: function($dropdown, $target) {

From 0d84a65ba2d715d0a7125abf335808e5c556deb9 Mon Sep 17 00:00:00 2001
From: Denis Sedchenko <ascii@live.ru>
Date: Thu, 16 Jun 2016 10:27:46 +0300
Subject: [PATCH 18/33] Watch removed items from 'select'

---
 jquery.dropdown.js | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 29c4bfe..2af664e 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -80,6 +80,9 @@
           $dynamicInput.find("input").attr("placeholder", options.dynamicOptLabel);
           $ul.append($dynamicInput);
         }
+
+
+
         // Cache the dropdown options
         var selectOptions = $dropdown.find("li");
 
@@ -88,10 +91,11 @@
             var $selected;
             if ($select.find(":selected").length) {
                 $selected = $select.find(":selected").last();
-            } else {
+            }
+            else {
                 $selected = $select.find("option, li").first();
+               // $selected = $select.find("option").first();
             }
-
             methods._select($dropdown, $selected);
         } else {
             var selectors = [], val = $select.val()
@@ -124,6 +128,8 @@
         // On click, set the clicked one as selected
         $ul.on("click", "li:not(.dropdownjs-add)", function(e) {
           methods._select($dropdown, $(this));
+          // trigger change event, if declared on the original selector
+          $select.change();
         });
         $ul.on("keydown", "li:not(.dropdownjs-add)", function(e) {
           if (e.which === 27) {
@@ -135,6 +141,7 @@
             return false;
           }
         });
+
         $ul.on("focus", "li:not(.dropdownjs-add)", function() {
           if ($select.is(":disabled")) {
             return;
@@ -167,6 +174,11 @@
 
         });
 
+        $select.on("DOMNodeRemoved", function(e) {
+          var deletedValue = e.target.getAttribute('value');
+          $ul.find("li[value='"+deletedValue+"']").remove();
+        });
+
         // Update dropdown when using val, need to use .val("value").trigger("change");
         $select.on("change", function(e) {
           var $this = $(e.target);
@@ -176,7 +188,8 @@
             var $selected;
             if ($select.find(":selected").length) {
               $selected = $select.find(":selected").last();
-            } else {
+            }
+            else {
               $selected = $select.find("option, li").first();
             }
             methods._select($dropdown, $selected);
@@ -272,7 +285,7 @@
         // Toggle option state
         $target.toggleClass("selected");
         // Toggle selection of the clicked option in native select
-        $target.each(function() {
+        $target.each(function(){
           var $selected = $select.find("[value=\"" + $(this).attr("value") + "\"]");
           $selected.prop("selected", $(this).hasClass("selected"));
         });
@@ -290,7 +303,7 @@
       if (!multi) {
         // Unselect options except the one that will be selected
         if ($target.is("li")) {
-          selectOptions.not($target).removeClass("selected");
+            selectOptions.not($target).removeClass("selected");
         }
         // Select the selected option
         $target.addClass("selected");
@@ -309,10 +322,14 @@
         }
       }
 
-      // Call the callback
-      if (this.options.onSelected) {
-        this.options.onSelected($target.attr("value"));
-      }
+       // Call the callback
+        if (this.options.onSelected) {
+            this.options.onSelected($target.attr("value"));
+        }
+
+    },
+    _removeOption: function ($ul, $this) {
+      console.warn(arguments);
     },
     _addOption: function($ul, $this) {
       // Create the option

From 72f8dc6281c329994830731a8338508c07979863 Mon Sep 17 00:00:00 2001
From: Denis Sedchenko <ascii@live.ru>
Date: Thu, 16 Jun 2016 10:28:42 +0300
Subject: [PATCH 19/33] Remove unused test code

---
 jquery.dropdown.js | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 2af664e..bd7f777 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -328,9 +328,6 @@
         }
 
     },
-    _removeOption: function ($ul, $this) {
-      console.warn(arguments);
-    },
     _addOption: function($ul, $this) {
       // Create the option
       var $option = $("<li></li>");

From 8cc521493ad782944b802a3eda7ab03539ae9938 Mon Sep 17 00:00:00 2001
From: Denis Sedchenko <ascii@live.ru>
Date: Thu, 16 Jun 2016 11:05:19 +0300
Subject: [PATCH 20/33] Change items selection on option remove

---
 jquery.dropdown.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index bd7f777..fe8de70 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -20,6 +20,9 @@
       "autoinit": false,
       "callback": false,
       "onSelected": false,
+      "destroy": function(element) {
+        this.destroy(element);
+      },
       "dynamicOptLabel": "Add a new option..."
     },
     init: function(options) {
@@ -177,6 +180,18 @@
         $select.on("DOMNodeRemoved", function(e) {
           var deletedValue = e.target.getAttribute('value');
           $ul.find("li[value='"+deletedValue+"']").remove();
+          var $selected;
+
+          setTimeout(function () {
+            if ($select.find(":selected").length) {
+              $selected = $select.find(":selected").last();
+            }
+            else {
+              $selected = $select.find("option, li").first();
+            }
+            methods._select($dropdown, $selected);
+          }, 100);
+
         });
 
         // Update dropdown when using val, need to use .val("value").trigger("change");

From eeaa3015ccf264ec7c209799b194f7d0e1d47340 Mon Sep 17 00:00:00 2001
From: Denis Sedchenko <ascii@live.ru>
Date: Thu, 16 Jun 2016 11:05:34 +0300
Subject: [PATCH 21/33] Add 'destroy' function

---
 jquery.dropdown.js | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index fe8de70..72ba0c5 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -382,10 +382,14 @@
       } else {
         $ul.append($option);
       }
+    },
+    destroy: function($e) {
+      $($e).show().removeAttr('data-dropdownjs').next('.dropdownjs').remove();
     }
   };
 
   $.fn.dropdown = function(params) {
+    if( typeof methods[params] == 'function' ) methods[params](this);
     if (methods[params]) {
       return methods[params].apply(this, Array.prototype.slice.call(arguments,1));
     } else if (typeof params === "object" | !params) {

From 7ab6c9ca7ac60c5937d5f18278866c28ebd9cafd Mon Sep 17 00:00:00 2001
From: Hasan Kumar <hasan@rocketbox.in>
Date: Wed, 22 Jun 2016 21:09:44 +0530
Subject: [PATCH 22/33] Allow setting $select.val('').change()

Fixes the issue where user is not able to set the dropdown value to blank programatically
---
 jquery.dropdown.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 29c4bfe..7f11d19 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -170,7 +170,6 @@
         // Update dropdown when using val, need to use .val("value").trigger("change");
         $select.on("change", function(e) {
           var $this = $(e.target);
-          if (!$this.val().length) return;
 
           if (!multi) {
             var $selected;

From 7e710ac11d23710e63e2ff2208e812ec919bfa8c Mon Sep 17 00:00:00 2001
From: Vahid Mohammad Taheri <vmtco.com@gmail.com>
Date: Sat, 10 Sep 2016 07:54:05 +0430
Subject: [PATCH 23/33] add RTL support

---
 jquery.dropdown.css | 27 +++++++++++++++++++++++++++
 jquery.dropdown.js  |  4 ++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/jquery.dropdown.css b/jquery.dropdown.css
index ee3903d..4ccb99c 100644
--- a/jquery.dropdown.css
+++ b/jquery.dropdown.css
@@ -95,3 +95,30 @@ select[data-dropdownjs][disabled] + .dropdownjs > input[readonly] {
 .dropdownjs > ul > li:h > .close:hover:before {
   opacity: .9;
 }
+
+.rtl .dropdownjs > input{
+	padding-right: 0;
+	padding-left: 30px;
+}
+
+.rtl .dropdownjs > ul[placement=top-right] {
+  -webkit-transform-origin: bottom right;
+      -ms-transform-origin: bottom right;
+          transform-origin: bottom right;
+  bottom: 0;
+  left: auto;
+  right: 0;
+}
+.rtl .dropdownjs > ul[placement=bottom-right] {
+  -webkit-transform-origin: top right;
+      -ms-transform-origin: top right;
+          transform-origin: top right;
+  top: 0;
+  left: auto;
+  right: 0;
+}
+.rtl .dropdownjs > ul > li > .close:before {
+  right: auto;
+  left: 15px;
+  float: left;
+}
\ No newline at end of file
diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 9dbbd22..dc62ccb 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -236,9 +236,9 @@
           // Decide if place the dropdown below or above the input
           if (height < 200 && coords.top > coords.bottom) {
             height = coords.top;
-            $ul.attr("placement", "top-left");
+            $ul.attr("placement", $("body").hasClass("rtl") ? "top-right" : "top-left");
           } else {
-            $ul.attr("placement", "bottom-left");
+            $ul.attr("placement", $("body").hasClass("rtl") ? "bottom-right" : "bottom-left");
           }
 
           $(this).next("ul").css("max-height", height - 20);

From e14cbb1b6bf2675e2ccdc521a4cdb795422e3401 Mon Sep 17 00:00:00 2001
From: Vahid Mohammad Taheri <vmtco.com@gmail.com>
Date: Sat, 17 Sep 2016 11:25:14 +0430
Subject: [PATCH 24/33] fixed bug

---
 jquery.dropdown.css | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jquery.dropdown.css b/jquery.dropdown.css
index 4ccb99c..5aa363f 100644
--- a/jquery.dropdown.css
+++ b/jquery.dropdown.css
@@ -92,7 +92,7 @@ select[data-dropdownjs][disabled] + .dropdownjs > input[readonly] {
   text-shadow: 0 1px 0 #fff;
   opacity: .6;
 }
-.dropdownjs > ul > li:h > .close:hover:before {
+.dropdownjs > ul > li:hover > .close:hover:before {
   opacity: .9;
 }
 

From 57179986edf7014059d0e14cb5f2825befb78358 Mon Sep 17 00:00:00 2001
From: Eugene Ivanov <Worldrider0100@gmail.com>
Date: Mon, 26 Sep 2016 16:09:42 +0300
Subject: [PATCH 25/33] fix #35

worked for me
---
 jquery.dropdown.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 9dbbd22..ae811bb 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -106,7 +106,9 @@
               selectors.push('li[value=' + val[i] + ']')
             }
             if (selectors.length > 0) {
-              methods._select($dropdown, $dropdown.find(selectors.join(',')));
+              var $target = $dropdown.find(selectors.join(','));
+              $target.removeClass("selected");
+              methods._select($dropdown, $target);
             }
         }
 
@@ -208,7 +210,7 @@
             }
             methods._select($dropdown, $selected);
           } else {
-            methods._select($dropdown, $select.find(":selected"));
+            // methods._select($dropdown, $select.find(":selected"));
           }
         });
 

From 0aee6dc0264578949d290260e38bd31fe3d332d4 Mon Sep 17 00:00:00 2001
From: Sullivan Perrin <SullyP@users.noreply.github.com>
Date: Thu, 29 Dec 2016 15:57:57 +0100
Subject: [PATCH 26/33] Fix : MultiSelect no updating when original change

MultiSelect Dropdown.js no updating when original multiselect change.
---
 jquery.dropdown.js | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index ae811bb..6c1be61 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -210,7 +210,14 @@
             }
             methods._select($dropdown, $selected);
           } else {
-            // methods._select($dropdown, $select.find(":selected"));
+            var target = $select.find(":selected");
+            // Unselect all options
+            selectOptions.removeClass("selected");
+            // Select options
+            target.each(function () {
+                var selected = selectOptions.filter("[value=\"" + $(this).attr("value") + "\"]");
+                selected.addClass("selected");
+            });
           }
         });
 

From 0eb2b1e2205da58430d0c472661be4b0313db4e0 Mon Sep 17 00:00:00 2001
From: Sullivan Perrin <SullyP@users.noreply.github.com>
Date: Wed, 15 Feb 2017 11:16:11 +0100
Subject: [PATCH 27/33] Fix autoinit filter

---
 jquery.dropdown.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 6c1be61..0b049c8 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -274,11 +274,11 @@
           if (!$this.is("select")) {
             $this = $this.find('select');
           }
-          if ($this.is(options.autoinit)) {
             $this.each(function() {
-              initElement($(this));
+                if ($(this).is(options.autoinit)) {
+                    initElement($(this));
+                }
             });
-          }
         });
       }
 

From b6eb485791dd6a681add5338535ea2e1362bcf6d Mon Sep 17 00:00:00 2001
From: Vishal Vishwakarma <vishal@corientbs.com>
Date: Fri, 17 Feb 2017 22:45:51 +0530
Subject: [PATCH 28/33] Disabled functionality added

---
 jquery.dropdown.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 0b049c8..16abc78 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -264,6 +264,9 @@
 
           // Close opened dropdowns
           $(".dropdownjs > ul > li").attr("tabindex", -1);
+          if (e.target.getAttribute('disabled')) {
+          return;
+        }
           $input.removeClass("focus");
         });
       }
@@ -292,6 +295,7 @@
       methods._select($(this), $target);
     },
     _select: function($dropdown, $target) {
+
       if ($target.is(".dropdownjs-add")) return;
 
       // Get dropdown's elements
@@ -324,6 +328,9 @@
 
       // Behavior for single select
       if (!multi) {
+        if ($target.attr("disabled")) {
+          return;
+        }
         // Unselect options except the one that will be selected
         if ($target.is("li")) {
             selectOptions.not($target).removeClass("selected");
@@ -384,6 +391,11 @@
         $option.addClass("selected");
       }
 
+      if ($this.prop("disabled")) {
+        $option.attr("disabled", true);
+        $option.addClass("disabled");
+      }
+
       // Append option to our dropdown
       if ($ul.find(".dropdownjs-add").length) {
         $ul.find(".dropdownjs-add").before($option);

From 3a3e82b9f4325bdc32ce0f69d88e6bb461ac0dce Mon Sep 17 00:00:00 2001
From: Vishal Vishwakarma <vishal@corientbs.com>
Date: Mon, 20 Feb 2017 13:57:35 +0530
Subject: [PATCH 29/33] Did suggested changes

---
 jquery.dropdown.js | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 16abc78..11cfcd0 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -264,8 +264,8 @@
 
           // Close opened dropdowns
           $(".dropdownjs > ul > li").attr("tabindex", -1);
-          if (e.target.getAttribute('disabled')) {
-          return;
+            if ($(e.target).hasClass('disabled')) {
+              return;
         }
           $input.removeClass("focus");
         });
@@ -392,7 +392,6 @@
       }
 
       if ($this.prop("disabled")) {
-        $option.attr("disabled", true);
         $option.addClass("disabled");
       }
 

From 8f4802573804f0b30c19ec91fb36ee6aaceb403b Mon Sep 17 00:00:00 2001
From: Vishal Vishwakarma <vishal@corientbs.com>
Date: Mon, 20 Feb 2017 14:00:18 +0530
Subject: [PATCH 30/33] Minor Fix

---
 jquery.dropdown.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 11cfcd0..5d796db 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -328,7 +328,7 @@
 
       // Behavior for single select
       if (!multi) {
-        if ($target.attr("disabled")) {
+        if ($target.hasClass("disabled")) {
           return;
         }
         // Unselect options except the one that will be selected

From 71267a708f5c005fc0a151592ea22cdaaa55b320 Mon Sep 17 00:00:00 2001
From: Vishal Vishwakarma <vishal@corientbs.com>
Date: Mon, 20 Feb 2017 14:23:03 +0530
Subject: [PATCH 31/33] Changed some javascript syntax to jquery

---
 jquery.dropdown.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index 5d796db..d381764 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -180,7 +180,7 @@
         });
 
         $select.on("DOMNodeRemoved", function(e) {
-          var deletedValue = e.target.getAttribute('value');
+          var deletedValue = $(e.target).attr('value');
           $ul.find("li[value='"+deletedValue+"']").remove();
           var $selected;
 

From f04bfd7dae1c43dbcbd263cb394144f5364e7d45 Mon Sep 17 00:00:00 2001
From: Chris Reynoso <freedommercenary@gmail.com>
Date: Wed, 19 Apr 2017 08:06:35 -0700
Subject: [PATCH 32/33] Fix li elements incorrectly using non-integer values
 for value attr and instead use data-value.

---
 jquery.dropdown.js | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index fcc2188..dc75619 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -103,10 +103,10 @@
         } else {
             var selectors = [], val = $select.val()
             for (var i in val) {
-              selectors.push('li[value=' + val[i] + ']')
+              selectors.push(val[i]);
             }
             if (selectors.length > 0) {
-              var $target = $dropdown.find(selectors.join(','));
+              var $target = $dropdown.find(function() { return $.inArray($(this).data("value"), selectors) !== -1; });
               $target.removeClass("selected");
               methods._select($dropdown, $target);
             }
@@ -181,7 +181,7 @@
 
         $select.on("DOMNodeRemoved", function(e) {
           var deletedValue = $(e.target).attr('value');
-          $ul.find("li[value='"+deletedValue+"']").remove();
+          $ul.find("li").filter(function() { return $(this).data("value") === deletedValue; }).remove();
           var $selected;
 
           setTimeout(function () {
@@ -210,12 +210,13 @@
             }
             methods._select($dropdown, $selected);
           } else {
-            var target = $select.find(":selected");
+            var target = $select.find(":selected"),
+                values = $(this).val();
             // Unselect all options
             selectOptions.removeClass("selected");
             // Select options
             target.each(function () {
-                var selected = selectOptions.filter("[value=\"" + $(this).attr("value") + "\"]");
+                var selected = selectOptions.filter(function() { return $.inArray($(this).data("value"), values) !== -1; });
                 selected.addClass("selected");
             });
           }
@@ -291,7 +292,7 @@
       });
     },
     select: function(target) {
-      var $target = $(this).find("[value=\"" + target + "\"]");
+      var $target = $(this).find(function() { return $(this).data("value") === target; });
       methods._select($(this), $target);
     },
     _select: function($dropdown, $target) {
@@ -313,17 +314,17 @@
         $target.toggleClass("selected");
         // Toggle selection of the clicked option in native select
         $target.each(function(){
-          var $selected = $select.find("[value=\"" + $(this).attr("value") + "\"]");
+          var $selected = $select.find("[value=\"" + $(this).data("value") + "\"]");
           $selected.prop("selected", $(this).hasClass("selected"));
         });
         // Add or remove the value from the input
         var text = [];
         selectOptions.each(function() {
           if ($(this).hasClass("selected")) {
-            text.push($(this).text());
+            text.push($(this).data("value"));
           }
         });
-        $input.val(text.join(", "));
+        $input.val(text.join(","));
       }
 
       // Behavior for single select
@@ -338,7 +339,7 @@
         // Select the selected option
         $target.addClass("selected");
         // Set the value to the native select
-        $select.val($target.attr("value"));
+        $select.val($target.data("value"));
         // Set the value to the input
         $input.val($target.text().trim());
       }
@@ -354,7 +355,7 @@
 
        // Call the callback
         if (this.options.onSelected) {
-            this.options.onSelected($target.attr("value"));
+            this.options.onSelected($target.data("value"));
         }
 
     },
@@ -374,7 +375,7 @@
         $option.html("&nbsp;");
       }
       // Set the value of the option
-      $option.attr("value", $this.val());
+      $option.data("value", $this.val());
 
       // Will user be able to remove this option?
       if ($ul.data("select").attr("data-dynamic-opts")) {
@@ -419,3 +420,4 @@
   };
 
 }));
+

From aa6be3fa10eaabfc244b4fbef33db9f985eb1b04 Mon Sep 17 00:00:00 2001
From: Chris Reynoso <freedommercenary@gmail.com>
Date: Wed, 19 Apr 2017 13:35:57 -0700
Subject: [PATCH 33/33] Add additional check for handling both option and li
 element values in select method. Add check to prevent double firing change
 event.

---
 jquery.dropdown.js | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/jquery.dropdown.js b/jquery.dropdown.js
index dc75619..5d69ca7 100644
--- a/jquery.dropdown.js
+++ b/jquery.dropdown.js
@@ -314,17 +314,18 @@
         $target.toggleClass("selected");
         // Toggle selection of the clicked option in native select
         $target.each(function(){
-          var $selected = $select.find("[value=\"" + $(this).data("value") + "\"]");
+          var value = $(this).prop("tagName") === "OPTION" ? $(this).val() : $(this).data("value"),
+              $selected = $select.find("[value=\"" + value + "\"]");
           $selected.prop("selected", $(this).hasClass("selected"));
         });
         // Add or remove the value from the input
         var text = [];
         selectOptions.each(function() {
           if ($(this).hasClass("selected")) {
-            text.push($(this).data("value"));
+            text.push($(this).text());
           }
         });
-        $input.val(text.join(","));
+        $input.val(text.join(", "));
       }
 
       // Behavior for single select
@@ -338,10 +339,17 @@
         }
         // Select the selected option
         $target.addClass("selected");
-        // Set the value to the native select
-        $select.val($target.data("value"));
         // Set the value to the input
         $input.val($target.text().trim());
+        var value = $target.prop("tagName") === "OPTION" ? $target.val() : $target.data("value");
+        // When val is set below on $select, it will fire change event,
+        // which ends up back here, make sure to not end up in an infinite loop.
+        // This is done last so text input is initialized on first load when condition is true.
+        if (value === $select.val()) {
+          return;
+        }
+        // Set the value to the native select
+        $select.val(value);
       }
 
       // This is used only if Material Design for Bootstrap is selected
@@ -353,10 +361,10 @@
         }
       }
 
-       // Call the callback
-        if (this.options.onSelected) {
-            this.options.onSelected($target.data("value"));
-        }
+      // Call the callback
+      if (this.options.onSelected) {
+        this.options.onSelected($target.data("value"));
+      }
 
     },
     _addOption: function($ul, $this) {
