Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue #21: placeholderOption & placeholder breaks SOD on mobil… #40

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions _src/selectordie.angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var app = angular.module('selectordie', []);

app.directive('selectordie', function($timeout) {
return {
restrict: 'A',
require: 'ngModel',
compile: function (tElement, tAttrs) {
return function (scope, element, attrs, ngModel) {
$timeout(function() {
element.find('select').selectOrDie({
placeholder: attrs.label ? attrs.label : null,
onChange: function() {
ngModel.$setViewValue($(this).val());
}
});
});
ngModel.$render = function() {
element.find('select').val(ngModel.$modelValue);
element.find('select option[value="' + ngModel.$modelValue + '"]').attr('selected', 'selected');
element.find('select').selectOrDie('update');
};
}
}
};
});
43 changes: 38 additions & 5 deletions _src/selectordie.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*
* Oddny | Cogs 'n Kegs
*
* @preserve
*
* =========================================================== */

; (function ($) {
Expand All @@ -32,7 +34,8 @@
linksExternal: false, // Boolean - false by default - Should the options be treated as links and open in a new window/tab?
size: 0, // Integer - 0 by default - The value set equals the amount of items before scroll is needed
tabIndex: 0, // integer - 0 by default
onChange: $.noop // Adds a callback function for when the SoD gets changed
onChange: $.noop, // Adds a callback function for when the SoD gets changed
forceNative: false // Forces native select
},
$_settings = {},
$_sodKeysWhenClosed = false,
Expand All @@ -58,6 +61,7 @@
$settingsSize = parseInt($select.data("size")) ? $select.data("size") : $_settings.size,
$settingsTabIndex = parseInt($select.data("tabindex")) ? $select.data("tabindex") : ( $_settings.tabIndex ? $_settings.tabIndex : ( $select.attr("tabindex") ? $select.attr("tabindex") : $_settings.tabIndex ) ),
$settingsStripEmpty = $select.data("strip-empty") ? $select.data("strip-empty") : $_settings.stripEmpty,
$forceNative = $select.data("force-native") ? $select.data("force-native") : $_settings.forceNative,
$selectTitle = $select.prop("title") ? $select.prop("title") : null,
$selectDisabled = $select.is(":disabled") ? " disabled" : "",
$sodPrefix = "",
Expand Down Expand Up @@ -95,7 +99,7 @@
}).insertAfter( this );

// If it's a touch device
if ( _private.isTouch() ) {
if ( _private.isTouch() || $forceNative ) {
$sod.addClass("touch");
}

Expand Down Expand Up @@ -470,7 +474,7 @@
$optionSelected.addClass("active");
}

if ( !$optionHasChanged && $sodPlaceholder ) {
if ( !$optionHasChanged && $sodPlaceholder && !$sod.hasClass('touch') ) {
$sod.find(".sod_label").get(0).lastChild.nodeValue = $optionSelected.text();
} else if ( !$optionHasChanged ) {
$sod.find(".sod_label").get(0).lastChild.nodeValue = $sodLabel;
Expand Down Expand Up @@ -553,7 +557,7 @@


update: function () {
return this.each(function () {
this.each(function () {
var $select = $(this),
$sod = $select.parent(),
$sodList = $sod.find(".sod_list:first");
Expand All @@ -580,6 +584,7 @@
}
});

return methods['updateLabel'].apply(this);
}, // update


Expand Down Expand Up @@ -634,7 +639,35 @@
console.log("Select or Die: There's no SoD to enable");
}
});
} // enable
}, // enable


updateLabel: function() {
return this.each(function () {
var $select = $(this),
$sod = $select.parent(),
$sodPlaceholder = $sod.data("placeholder"),
$sodPlaceholderOption = $sod.data("placeholder-option"),
$sodPrefix = $sod.data("prefix"),
$sodLabel = $sod.find(".sod_label"),
$sodText = null;

if ($select.val()) {
$sodText = $select.find('option[value="' + $select.val() + '"]').text();
}
else {
if ($sodPlaceholderOption) {
$sodText = $select.find('option[value="' + $sodPlaceholderOption + '"]').text();
}
else {
$sodText = $sodPlaceholder;
}
$sodLabel.addClass("sod_placeholder");
}
$sod.data("label", $sodText);
$sodLabel.text($sodText);
});
} // updateLabel

};

Expand Down
Loading