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

fix #85 save label with update option #89

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ <h2>Default Label</h2>
<p>The default label will be displayed on initialization only if an option does not have the <code>selected</code> attribute explicitly defined.</p>

<pre class="example"><code class="language-javascript">$("select").selecter({
label: "Select An Item"
label: "Select A State"
});</code></pre>

<h5>Demo</h5>
Expand Down
2 changes: 1 addition & 1 deletion jquery.fs.selecter.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Selecter v3.2.4 - 2015-01-07
* Selecter v3.2.4 - 2015-01-16
* A jQuery plugin for replacing default select elements. Part of the Formstone Library.
* http://formstone.it/selecter/
*
Expand Down
37 changes: 18 additions & 19 deletions jquery.fs.selecter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Selecter v3.2.4 - 2015-01-07
* Selecter v3.2.4 - 2015-01-16
* A jQuery plugin for replacing default select elements. Part of the Formstone Library.
* http://formstone.it/selecter/
*
Expand Down Expand Up @@ -143,33 +143,35 @@


/**
* @method private
* @name refresh
* @description DEPRECATED - Updates instance base on target options
* @example $(".target").selecter("refresh");
*/
* @method private
* @name refresh
* @description DEPRECATED - Updates instance base on target options
* @example $(".target").selecter("refresh");
*/
refresh: function() {
return pub.update.apply($(this));
},

/**
* @method
* @name update
* @description Updates instance base on target options
* @example $(".target").selecter("update");
*/
* @method
* @name update
* @description Updates instance base on target options
* @example $(".target").selecter("update");
*/
update: function() {
return $(this).each(function(i, input) {
var data = $(input).parent(".selecter").data("selecter");

if (data) {
var index = data.index;
if (data.label) {
data.$select.prepend('<option value="" class="selecter-placeholder">' + data.label + '</option>');
}

data.$allOptions = data.$select.find("option, optgroup");
data.$options = data.$allOptions.filter("option");
data.index = -1;

index = data.$options.index(data.$options.filter(":selected"));
var index = data.$options.index(data.$options.filter(":selected"));

_buildOptions(data);

Expand Down Expand Up @@ -240,14 +242,13 @@
var $allOptions = $select.find("option, optgroup"),
$options = $allOptions.filter("option");

// If we didn't actually have a selected elemtn
// If we didn't actually have a selected element
if (!$originalOption.length) {
$originalOption = $options.eq(0);
}

// Determine original item
var originalIndex = (originalOptionIndex > -1) ? originalOptionIndex : 0,
originalLabel = (opts.label !== "") ? opts.label : $originalOption.text(),
wrapperTag = "div";

// Swap tab index, no more interacting with the actual select!
Expand Down Expand Up @@ -279,9 +280,7 @@

// Build inner
if (!opts.multiple) {
inner += '<span class="selecter-selected">';
inner += $('<span></span>').text( _trim(originalLabel, opts.trim) ).html();
inner += '</span>';
inner += '<span class="selecter-selected"></span>';
}
inner += '<div class="selecter-options">';
inner += '</div>';
Expand Down Expand Up @@ -747,7 +746,7 @@
$item.addClass("selected");
data.index = index;
} else if (data.label !== "") {
data.$selected.html(data.label);
data.$selected.html( _trim(data.label, data.trim) );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion jquery.fs.selecter.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading