Permalink
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	index.html
	jquery.dropdown.css
	jquery.dropdown.js
  • Loading branch information...
2 parents caa8336 + 6857425 commit 4e7077474c63f6d5c0a687c9df10f3da7f94cb88 FezVrasta committed Dec 29, 2014
Showing with 31 additions and 15 deletions.
  1. +6 −4 jquery.dropdown.css
  2. +25 −11 jquery.dropdown.js
View
@@ -5,8 +5,7 @@
box-sizing: border-box;
}
.dropdownjs > input {
- width: 100%;
- cursor: pointer !important;
+ width: 100%;
}
.dropdownjs > input.focus ~ ul {
transform: scale(1);
@@ -36,8 +35,11 @@
/* Theme */
-.dropdownjs > input {
- cursor: pointer;
+.dropdownjs > input[readonly] {
+ cursor: pointer;
+}
+select[data-dropdownjs][disabled] + .dropdownjs > input[readonly] {
+ cursor: default;
}
.dropdownjs > ul {
background: #FFF;
View
@@ -12,7 +12,11 @@
init: function(options) {
// Apply user options if user has defined some
- options = (options) ? $.extend(methods.options, options) : methods.options;
+ if (options) {
+ options = $.extend(methods.options, options);
+ } else {
+ options = methods.options;
+ }
function initElement($select) {
// Don't do anything if this is not a select or if this select was already initialized
@@ -54,9 +58,6 @@
// Style the option
$option.addClass(options.optionStyle);
- // Save the original option inside the li element
- $option.data("option", $this);
-
// If the option has some text then transfer it
if ($this.text()) {
$option.text($this.text());
@@ -98,7 +99,7 @@
$input.addClass($select[0].className);
// Hide the old and ugly select
- $select.hide().data("dropdownjs", true);
+ $select.hide().attr("data-dropdownjs", true);
// Bring to life our awesome dropdownjs
$select.after($dropdown);
@@ -115,6 +116,8 @@
// On click, set the clicked one as selected
selectOptions.on("click", function(e) {
methods._select($dropdown, $(this));
+ // trigger change event, if declared on the original selector
+ $select.change();
});
selectOptions.on("keydown", function(e) {
if (e.which === 27) {
@@ -128,12 +131,18 @@
});
selectOptions.on("focus", function() {
+ if ($select.is(":disabled")) {
+ return;
+ }
$input.addClass("focus");
});
// Used to make the dropdown menu more dropdown-ish
$input.on("click focus", function(e) {
e.stopPropagation();
+ if ($select.is(":disabled")) {
+ return;
+ }
$(".dropdownjs > ul > li").each(function() { $(this).attr("tabindex", -1); });
$(".dropdownjs > input").not($(this)).removeClass("focus").blur();
@@ -200,11 +209,12 @@
// Toggle option state
$target.toggleClass("selected");
// Toggle selection of the clicked option in native select
- var $selected = $target.data("option");
- if ($selected[0]) {
- $selected[0].selected = !$selected[0].selected;
+ var $selected = $select.find("[value=\"" + $target.attr("value") + "\"]");
+ if ($selected.attr("selected")) {
+ $selected.attr("selected", true);
+ } else {
+ $selected.attr("selected", false);
}
- $select.trigger("change");
// Add or remove the value from the input
var text = [];
selectOptions.each(function() {
@@ -222,14 +232,18 @@
// Select the selected option
$target.addClass("selected");
// Set the value to the native select
- $select.val($target.attr("value")).trigger("change");
+ $select.val($target.attr("value"));
// Set the value to the input
$input.val($target.text());
}
// This is used only if Material Design for Bootstrap is selected
if ($.material) {
- $select.toggleClass("empty", !$input.val().trim());
+ if ($input.val().trim()) {
+ $select.removeClass("empty");
+ } else {
+ $select.addClass("empty");
+ }
}
}

0 comments on commit 4e70774

Please sign in to comment.