Permalink
...
Comparing changes
Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .
Open a pull request
Create a new pull request by comparing changes across two branches. If you need to, you can also .
Choose a Base Repository
FezVrasta/dropdown.js
497480098/dropdown.js
Bethuell/dropdown.js
BionicClick/dropdown.js
BoserFront/dropdown.js
EReyes-TILD/dropdown.js
FabricioElias/dropdown.js
FreedomMercenary/dropdown.js
Frenzy7/dropdown.js
Hamper/dropdown.js
HeribertoME/dropdown.js
ImNitinNayar7/dropdown.js
Isabellle/dropdown.js
PsyStorm25/dropdown.js
RamiDzPower/dropdown.js
RendellD/dropdown.js
S2iL/dropdown.js
SullyP/dropdown.js
Tymecode/dropdown.js
Worldrider/dropdown.js
WunGCQ/dropdown.js
YoungLiao/dropdown.js
aferrando/dropdown.js
ahmedali5530/dropdown.js
ajitsinghit2/dropdown.js
annirak/dropdown.js
arunpoudel/dropdown.js
atifzaidi/dropdown.js
bmla/dropdown.js
brentini/dropdown.js
chSkull/dropdown.js
chelsiideguzman/dropdown.js
chtrinh/dropdown.js
corientdev/dropdown.js
cphantom/dropdown.js
creativeprogramming/dropdown.js
daranas/dropdown.js
davidhynek/dropdown.js
develjs/dropdown.js
din982/dropdown.js
dropfen/dropdown.js
duckster/dropdown.js
genzj/dropdown.js
georgezambrano/dropdown.js
joelmm1/dropdown.js
jonasdk/dropdown.js
kennynaoh/dropdown.js
ketancmarix/dropdown.js
liesislukas/dropdown.js
lilkid/dropdown.js
liunanqi/dropdown.js
lpdhacker/dropdown.js
madalinignisca/dropdown.js
magikozio/dropdown.js
minhhuynh96/dropdown.js
mintuhouse/dropdown.js
mzhang444/dropdown.js
nekkon/dropdown.js
odin3/dropdown.js
ookami-kb/dropdown.js
pandazzurro/dropdown.js
parinpan/dropdown.js
pekapa/dropdown.js
perdona/dropdown.js
phbule/dropdown.js
pkdevboxy/dropdown.js
praneeth1249/dropdown.js
regianegmelo/dropdown.js
rsnemesis/dropdown.js
sanjaykumar27/dropdown.js
sektlab/dropdown.js
sgtshellback/dropdown.js
siddht1/dropdown.js
smbeiragh/dropdown.js
socialwears/dropdown.js
spinapplications/dropdown.js
srinivashappy/dropdown.js
stephane-monnot/dropdown.js
suz100231/dropdown.js
svdovichenko/dropdown.js
tasonface/dropdown.js
techtronics/dropdown.js
virusjambo/dropdown.js
vmtco/dropdown.js
wad2eq/dropdown.js
wizston/dropdown.js
yaraq64/dropdown.js
yashilanka/dropdown.js
Nothing to show
Choose a Head Repository
FezVrasta/dropdown.js
497480098/dropdown.js
Bethuell/dropdown.js
BionicClick/dropdown.js
BoserFront/dropdown.js
EReyes-TILD/dropdown.js
FabricioElias/dropdown.js
FreedomMercenary/dropdown.js
Frenzy7/dropdown.js
Hamper/dropdown.js
HeribertoME/dropdown.js
ImNitinNayar7/dropdown.js
Isabellle/dropdown.js
PsyStorm25/dropdown.js
RamiDzPower/dropdown.js
RendellD/dropdown.js
S2iL/dropdown.js
SullyP/dropdown.js
Tymecode/dropdown.js
Worldrider/dropdown.js
WunGCQ/dropdown.js
YoungLiao/dropdown.js
aferrando/dropdown.js
ahmedali5530/dropdown.js
ajitsinghit2/dropdown.js
annirak/dropdown.js
arunpoudel/dropdown.js
atifzaidi/dropdown.js
bmla/dropdown.js
brentini/dropdown.js
chSkull/dropdown.js
chelsiideguzman/dropdown.js
chtrinh/dropdown.js
corientdev/dropdown.js
cphantom/dropdown.js
creativeprogramming/dropdown.js
daranas/dropdown.js
davidhynek/dropdown.js
develjs/dropdown.js
din982/dropdown.js
dropfen/dropdown.js
duckster/dropdown.js
genzj/dropdown.js
georgezambrano/dropdown.js
joelmm1/dropdown.js
jonasdk/dropdown.js
kennynaoh/dropdown.js
ketancmarix/dropdown.js
liesislukas/dropdown.js
lilkid/dropdown.js
liunanqi/dropdown.js
lpdhacker/dropdown.js
madalinignisca/dropdown.js
magikozio/dropdown.js
minhhuynh96/dropdown.js
mintuhouse/dropdown.js
mzhang444/dropdown.js
nekkon/dropdown.js
odin3/dropdown.js
ookami-kb/dropdown.js
pandazzurro/dropdown.js
parinpan/dropdown.js
pekapa/dropdown.js
perdona/dropdown.js
phbule/dropdown.js
pkdevboxy/dropdown.js
praneeth1249/dropdown.js
regianegmelo/dropdown.js
rsnemesis/dropdown.js
sanjaykumar27/dropdown.js
sektlab/dropdown.js
sgtshellback/dropdown.js
siddht1/dropdown.js
smbeiragh/dropdown.js
socialwears/dropdown.js
spinapplications/dropdown.js
srinivashappy/dropdown.js
stephane-monnot/dropdown.js
suz100231/dropdown.js
svdovichenko/dropdown.js
tasonface/dropdown.js
techtronics/dropdown.js
virusjambo/dropdown.js
vmtco/dropdown.js
wad2eq/dropdown.js
wizston/dropdown.js
yaraq64/dropdown.js
yashilanka/dropdown.js
Nothing to show
19
contributors
Commits on Jan 11, 2015
|
dropfen |
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. |
61000dc
|
|||
|
Fez Vrasta |
Merge pull request #4 from dropfen/master
Call attr() instead of prop() to set it to selected |
5c371cd
|
Commits on Mar 03, 2015
|
jesusprubio |
UDM support added (CommonJS/Browserify included)
|
663d3c2
|
|||
|
Fez Vrasta |
Merge pull request #12 from jesusprubio/master
UDM support added (CommonJS/Browserify included) |
4e258ec
|
Commits on Apr 22, 2015
|
arunpoudel |
Fixes ":selected" attribute not being honoured
selected attribute of the option wasn't being honoured because the selector passed was wrong. |
dcd58f1
|
|||
|
arunpoudel |
Merge pull request #1 from arunpoudel/select-patch-1
Fixes ":selected" attribute not being honoured |
e813d81
|
|||
|
Fez Vrasta |
Merge pull request #13 from arunpoudel/master
:selected attribute not being honoured |
3fe2693
|
Commits on Jun 04, 2015
|
NVentimiglia |
Update jquery.dropdown.js
Fix for <select> elements |
a540c62
|
Commits on Jun 07, 2015
|
NVentimiglia |
onSelected event handler
onSelected event handler |
e2e83f7
|
Commits on Jun 20, 2015
|
liesislukas |
Update jquery.dropdown.js
trim'ing blankspace coming from html |
0b13f80
|
Commits on Jun 25, 2015
|
Fez Vrasta |
Merge pull request #18 from liesislukas/master
Bugfix for whitespace around selected option. |
8b2a1c2
|
Commits on Jul 01, 2015
|
Fez Vrasta |
Merge pull request #16 from NVentimiglia/master
Fix for <select> elements |
f08720b
|
Commits on Jul 21, 2015
|
Hamper |
autoinit nested selects
|
650c4cf
|
|||
|
Hamper |
fix multi selects init
|
5cfb2b1
|
Commits on Jul 22, 2015
|
Hamper |
fix
|
8e7e69b
|
Commits on Aug 04, 2015
|
Fez Vrasta |
autoprefixed
|
23613f9
|
|||
|
Fez Vrasta |
Merge pull request #22 from Hamper/master
autoinit nested selects |
96821bf
|
|||
|
nekkon |
.val+change fix
.val("value").trigger("change"); works with this change |
fbfeed5
|
Commits on Aug 06, 2015
|
Fez Vrasta |
Merge pull request #24 from nekkon/patch-1
.val+change fix |
09d23f5
|
Commits on Oct 31, 2015
|
arielbottero |
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 |
dec4fba
|
Commits on Nov 02, 2015
|
arielbottero |
Update jquery.dropdown.js
|
a08df5c
|
Commits on Nov 13, 2015
|
magikozio |
Update jquery.dropdown.js
|
b81ef15
|
|||
|
FezVrasta |
Merge pull request #32 from magikozio/fix-autoinit
Patch jquery.dropdown.js for autoselect |
046b566
|
|||
|
FezVrasta |
Merge pull request #30 from arielbottero/patch-2
jquery.dropdown.js |
9d36644
|
Commits on May 11, 2016
|
Chris Trinh |
dropdown class and option class apply the correct styles
|
b43d06e
|
|||
|
FezVrasta |
Merge pull request #41 from chtrinh/bugfix/dropdownClass_optionClass
dropdown class and option class apply the correct styles |
436bc89
|
Commits on May 12, 2016
|
Chris Trinh |
Fix bug causing onselected to be fired twice and fix formmatting
|
b227a5e
|
|||
|
Chris Trinh |
Remove console logging
|
aa6af20
|
Commits on Jun 14, 2016
|
FezVrasta |
Merge pull request #43 from chtrinh/bugfix/double_onselect_callback
Fix bug causing onselected to be fired twice and fix formmatting |
2555da7
|
Commits on Jun 16, 2016
|
odin3 |
Watch removed items from 'select'
|
0d84a65
|
|||
|
odin3 |
Remove unused test code
|
72f8dc6
|
|||
|
odin3 |
Change items selection on option remove
|
8cc5214
|
|||
|
odin3 |
Add 'destroy' function
|
eeaa301
|
Commits on Jun 22, 2016
|
Hasan Kumar |
Allow setting $select.val('').change()
Fixes the issue where user is not able to set the dropdown value to blank programatically |
7ab6c9c
|
Commits on Aug 15, 2016
|
FezVrasta |
Merge pull request #46 from mintuhouse/patch-1
Allow setting $select.val('').change() |
48c6630
|
|||
|
FezVrasta |
Merge pull request #45 from odin3/master
Watch removed items from select |
1a37034
|
Commits on Sep 10, 2016
|
vmtco |
add RTL support
|
7e710ac
|
Commits on Sep 17, 2016
|
vmtco |
fixed bug
|
e14cbb1
|
Commits on Sep 26, 2016
|
Worldrider |
fix #35
worked for me |
5717998
|
Commits on Oct 02, 2016
|
FezVrasta |
Merge pull request #51 from Worldrider/patch-1
fix #35 |
a22ee6f
|
Commits on Dec 29, 2016
|
SullyP |
Fix : MultiSelect no updating when original change
MultiSelect Dropdown.js no updating when original multiselect change. |
0aee6dc
|
|||
|
FezVrasta |
Merge pull request #57 from SullyP/patch-1
Fix : MultiSelect no updating when original change |
73b47e4
|
Commits on Feb 15, 2017
|
SullyP |
Fix autoinit filter
|
0eb2b1e
|
|||
|
FezVrasta |
Merge pull request #58 from SullyP/patch-1
Fix autoinit filter |
c22c969
|
Commits on Feb 17, 2017
|
corientdev |
Disabled functionality added
|
b6eb485
|
Commits on Feb 19, 2017
|
FezVrasta |
Merge pull request #50 from vmtco/master
add RTL support |
cf7d54b
|
Commits on Feb 20, 2017
Commits on Apr 19, 2017
|
FreedomMercenary |
Fix li elements incorrectly using non-integer values for value attr a…
…nd instead use data-value. |
f04bfd7
|
|||
|
FezVrasta |
Merge pull request #61 from FreedomMercenary/LiValueFix
Fix issue in IE for option values with dashes |
696bb9e
|
|||
|
FreedomMercenary |
Add additional check for handling both option and li element values i…
…n select method. Add check to prevent double firing change event. |
aa6be3f
|
|||
|
FezVrasta |
Merge pull request #62 from FreedomMercenary/LiValueFix
Correct select method not handling option and li elements |
868eb97
|
Unified
Split
Showing
with
214 additions
and 37 deletions.
- +16 −0 README.md
- +42 −6 jquery.dropdown.css
- +132 −31 jquery.dropdown.js
- +24 −0 package.json
View
16
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"}); | ||
+}); | ||
+... | ||
+``` |
View
48
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; | ||
@@ -83,6 +92,33 @@ 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; | ||
} | ||
+ | ||
+.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; | ||
+} |
View
163
jquery.dropdown.js
@@ -1,13 +1,28 @@ | ||
/* 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 : { | ||
"optionClass": "", | ||
"dropdownClass": "", | ||
"autoinit": false, | ||
"callback": false, | ||
+ "onSelected": false, | ||
+ "destroy": function(element) { | ||
+ this.destroy(element); | ||
+ }, | ||
"dynamicOptLabel": "Add a new option..." | ||
}, | ||
init: function(options) { | ||
@@ -34,7 +49,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 | ||
@@ -76,16 +91,25 @@ | ||
// 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]")); | ||
+ var selectors = [], val = $select.val() | ||
+ for (var i in val) { | ||
+ selectors.push(val[i]); | ||
+ } | ||
+ if (selectors.length > 0) { | ||
+ var $target = $dropdown.find(function() { return $.inArray($(this).data("value"), selectors) !== -1; }); | ||
+ $target.removeClass("selected"); | ||
+ methods._select($dropdown, $target); | ||
+ } | ||
} | ||
// Transfer the classes of the select to the input dropdown | ||
@@ -155,6 +179,49 @@ | ||
}); | ||
+ $select.on("DOMNodeRemoved", function(e) { | ||
+ var deletedValue = $(e.target).attr('value'); | ||
+ $ul.find("li").filter(function() { return $(this).data("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"); | ||
+ $select.on("change", function(e) { | ||
+ var $this = $(e.target); | ||
+ | ||
+ 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 { | ||
+ var target = $select.find(":selected"), | ||
+ values = $(this).val(); | ||
+ // Unselect all options | ||
+ selectOptions.removeClass("selected"); | ||
+ // Select options | ||
+ target.each(function () { | ||
+ var selected = selectOptions.filter(function() { return $.inArray($(this).data("value"), values) !== -1; }); | ||
+ selected.addClass("selected"); | ||
+ }); | ||
+ } | ||
+ }); | ||
+ | ||
// Used to make the dropdown menu more dropdown-ish | ||
$input.on("click focus", function(e) { | ||
e.stopPropagation(); | ||
@@ -179,9 +246,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); | ||
@@ -198,16 +265,24 @@ | ||
// Close opened dropdowns | ||
$(".dropdownjs > ul > li").attr("tabindex", -1); | ||
+ if ($(e.target).hasClass('disabled')) { | ||
+ return; | ||
+ } | ||
$input.removeClass("focus"); | ||
}); | ||
} | ||
if (options.autoinit) { | ||
$(document).on("DOMNodeInserted", function(e) { | ||
var $this = $(e.target); | ||
- if ($this.is("select") && $this.is(options.autoinit)) { | ||
- initElement($this); | ||
+ if (!$this.is("select")) { | ||
+ $this = $this.find('select'); | ||
} | ||
+ $this.each(function() { | ||
+ if ($(this).is(options.autoinit)) { | ||
+ initElement($(this)); | ||
+ } | ||
+ }); | ||
}); | ||
} | ||
@@ -217,16 +292,16 @@ | ||
}); | ||
}, | ||
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) { | ||
+ | ||
if ($target.is(".dropdownjs-add")) return; | ||
// Get dropdown's elements | ||
var $select = $dropdown.data("select"), | ||
$input = $dropdown.find("input.fakeinput"); | ||
- | ||
// Is it a multi select? | ||
var multi = $select.attr("multiple"); | ||
@@ -238,12 +313,11 @@ | ||
// 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 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() { | ||
@@ -256,14 +330,26 @@ | ||
// Behavior for single select | ||
if (!multi) { | ||
+ if ($target.hasClass("disabled")) { | ||
+ return; | ||
+ } | ||
// Unselect options except the one that will be selected | ||
- 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 | ||
- $select.val($target.attr("value")); | ||
// Set the value to the input | ||
- $input.val($target.text()); | ||
+ $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 | ||
@@ -275,13 +361,18 @@ | ||
} | ||
} | ||
+ // Call the callback | ||
+ if (this.options.onSelected) { | ||
+ this.options.onSelected($target.data("value")); | ||
+ } | ||
+ | ||
}, | ||
_addOption: function($ul, $this) { | ||
// Create the option | ||
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()) { | ||
@@ -292,7 +383,7 @@ | ||
$option.html(" "); | ||
} | ||
// 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")) { | ||
@@ -305,7 +396,12 @@ | ||
// Ss it selected? | ||
if ($this.prop("selected")) { | ||
- $option.prop("selected", true); | ||
+ $option.attr("selected", true); | ||
+ $option.addClass("selected"); | ||
+ } | ||
+ | ||
+ if ($this.prop("disabled")) { | ||
+ $option.addClass("disabled"); | ||
} | ||
// Append option to our dropdown | ||
@@ -314,10 +410,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) { | ||
@@ -327,4 +427,5 @@ | ||
} | ||
}; | ||
-})(jQuery); | ||
+})); | ||
+ |

Oops, something went wrong.
Showing you all comments on commits in this comparison.
This should be wrong cause |