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

Added data-selectedtext #151

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions demos/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@
<option value="a Stateful UI Widget">a Stateful UI Widget</option>
</optgroup>
</select>

<select name="test">
<option value="SelectBoxIt is:">SelectBoxIt is:</option>
<option data-selectedtext="SelectBoxIt is: a jQueryPlugin" value="a jQuery Plugin">a jQuery Plugin</option>
<option data-selectedtext="SelectBoxIt is: a Select Box Replacement" value="a Select Box Replacement">a Select Box Replacement</option>
<option data-selectedtext="SelectBoxIt is: a Stateful UI Widget" value="a Stateful UI Widget">a Stateful UI Widget</option>
</select>
</form>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
Expand Down
18 changes: 14 additions & 4 deletions src/javascripts/jquery.selectBoxIt.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@

}),

currentDataSelectedText,

currentDataText,

currentText;
Expand Down Expand Up @@ -474,6 +476,8 @@

iconUrlStyle = iconUrl ? 'style="background-image:url(\'' + iconUrl + '\');"': "",

currentDataSelectedText = $(this).attr("data-selectedtext"),

currentDataText = $(this).attr("data-text"),

currentText = currentDataText ? currentDataText: $(this).text();
Expand Down Expand Up @@ -503,7 +507,7 @@
if (this.selected) {

// Replaces the default text with the selected option text
self._setText(self.dropdownText, currentText);
self._setText(self.dropdownText, currentDataSelectedText || currentText);

//Set the currently selected option
self.currentFocus = index;
Expand Down Expand Up @@ -1313,7 +1317,8 @@
// `change` event handler with the `selectBoxIt` namespace
"change.selectBoxIt, internal-change.selectBoxIt": function(event, internal) {

var currentOption;
var currentOption,
currentDataSelectedText;

// If the user called the change method
if(!internal) {
Expand All @@ -1333,12 +1338,14 @@

currentOption = self.listItems.eq(self.currentFocus);

currentDataSelectedText = currentOption.attr("data-selectedtext");

currentDataText = currentOption.attr("data-text");

currentText = currentDataText ? currentDataText: currentOption.find("a").text();

// Sets the new dropdown list text to the value of the current option
self._setText(self.dropdownText, currentText);
self._setText(self.dropdownText, currentDataSelectedText || currentText);

self.dropdownText.attr("data-val", self.originalElem.value);

Expand Down Expand Up @@ -1383,12 +1390,15 @@
_update: function(elem) {

var self = this,
currentDataSelectedText,
currentDataText,
currentText,
defaultText = self.options["defaultText"] || self.selectBox.attr("data-text");

if (elem.attr("data-disabled") === "false") {

currentDataSelectedText = self.listItems.eq(self.currentFocus).attr("data-selectedtext");

currentDataText = self.listItems.eq(self.currentFocus).attr("data-text");

currentText = currentDataText ? currentDataText: self.listItems.eq(self.currentFocus).text();
Expand All @@ -1397,7 +1407,7 @@
if ((defaultText && self.options["html"] ? self.dropdownText.html() === defaultText: self.dropdownText.text() === defaultText) && self.selectBox.val() === elem.attr("data-val")) {

// Updates the dropdown list value
self._setText(self.dropdownText, currentText);
self._setText(self.dropdownText, currentDataSelectedText || currentText);

self.dropdownText.trigger("internal-change");

Expand Down
18 changes: 14 additions & 4 deletions src/javascripts/jquery.selectBoxIt.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@

}),

currentDataSelectedText,

currentDataText,

currentText;
Expand Down Expand Up @@ -474,6 +476,8 @@

iconUrlStyle = iconUrl ? 'style="background-image:url(\'' + iconUrl + '\');"': "",

currentDataSelectedText = $(this).attr("data-selectedtext"),

currentDataText = $(this).attr("data-text"),

currentText = currentDataText ? currentDataText: $(this).text();
Expand Down Expand Up @@ -503,7 +507,7 @@
if (this.selected) {

// Replaces the default text with the selected option text
self._setText(self.dropdownText, currentText);
self._setText(self.dropdownText, currentDataSelectedText || currentText);

//Set the currently selected option
self.currentFocus = index;
Expand Down Expand Up @@ -1313,7 +1317,8 @@
// `change` event handler with the `selectBoxIt` namespace
"change.selectBoxIt, internal-change.selectBoxIt": function(event, internal) {

var currentOption;
var currentOption,
currentDataSelectedText;

// If the user called the change method
if(!internal) {
Expand All @@ -1333,12 +1338,14 @@

currentOption = self.listItems.eq(self.currentFocus);

currentDataSelectedText = currentOption.attr("data-selectedtext");

currentDataText = currentOption.attr("data-text");

currentText = currentDataText ? currentDataText: currentOption.find("a").text();

// Sets the new dropdown list text to the value of the current option
self._setText(self.dropdownText, currentText);
self._setText(self.dropdownText, currentDataSelectedText || currentText);

self.dropdownText.attr("data-val", self.originalElem.value);

Expand Down Expand Up @@ -1383,12 +1390,15 @@
_update: function(elem) {

var self = this,
currentDataSelectedText,
currentDataText,
currentText,
defaultText = self.options["defaultText"] || self.selectBox.attr("data-text");

if (elem.attr("data-disabled") === "false") {

currentDataSelectedText = self.listItems.eq(self.currentFocus).attr("data-selectedtext");

currentDataText = self.listItems.eq(self.currentFocus).attr("data-text");

currentText = currentDataText ? currentDataText: self.listItems.eq(self.currentFocus).text();
Expand All @@ -1397,7 +1407,7 @@
if ((defaultText && self.options["html"] ? self.dropdownText.html() === defaultText: self.dropdownText.text() === defaultText) && self.selectBox.val() === elem.attr("data-val")) {

// Updates the dropdown list value
self._setText(self.dropdownText, currentText);
self._setText(self.dropdownText, currentDataSelectedText || currentText);

self.dropdownText.trigger("internal-change");

Expand Down
Loading