Skip to content

Commit

Permalink
Allow to show text in modal selector
Browse files Browse the repository at this point in the history
  • Loading branch information
db0company committed Aug 14, 2015
1 parent 2b6528d commit d2599c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cuteform.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
margin: 0 2px;
border: 3px solid #aaa;
}

.cuteform-modal-text:after {
content: ' ▼';
}
18 changes: 14 additions & 4 deletions cuteform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

function cuteformhtml(option, options) {
var value = option.val();
var text = option.text();
var image = typeof options['images'] !== 'undefined' && typeof options['images'][value] !== 'undefined' ? options['images'][value] : (typeof option.attr('data-cuteform-image') !== 'undefined' ? option.attr('data-cuteform-image') : null);
if (image !== null) {
return $('<img class="cuteform-elt" src="' + image + '" data-cuteform-val="' + value + '">');
return $('<img class="cuteform-elt" src="' + image + '" data-cuteform-val="' + value + '" data-cuteform-text="' + text + '">');
}
var html = typeof options['html'] !== 'undefined' && typeof options['html'][value] !== 'undefined' ? options['html'][value] : (typeof option.attr('data-cuteform-html') !== 'undefined' ? option.attr('data-cuteform-html') : value);
return $('<div class="cuteform-elt" data-cuteform-val="' + value + '">' + html + '</div>');
return $('<div class="cuteform-elt" data-cuteform-val="' + value + '" data-cuteform-text="' + text + '">' + html + '</div>');
}

function cuteform(select, options) {
Expand All @@ -19,6 +20,7 @@ function cuteform(select, options) {
var cuteform, modal, modal_button;
// Modal
var with_modal = options['modal'] == 'true' || select.attr('data-cuteform-modal') == 'true';
var with_modal_text = options['modal-text'] == 'true' || select.attr('data-cuteform-modal-text') == 'true';
if (with_modal) {
modal = $('<div class="cuteform modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"></div></div></div></div>');
cuteform = modal.find('.modal-body');
Expand Down Expand Up @@ -49,14 +51,22 @@ function cuteform(select, options) {
html.addClass('cuteform-selected');
if (with_modal) {
modal_button.text('');
modal_button.append(cuteform.find('.cuteform-selected').clone(true).off());
if (with_modal_text) {
modal_button.append('<span class="cuteform-modal-text">' + cuteform.find('.cuteform-selected').attr('data-cuteform-text') + '</span>');
} else {
modal_button.append(cuteform.find('.cuteform-selected').clone(true).off());
}
modal.modal('hide');
}
});
});
if (with_modal) {
// Change the content of the modal button and bind click
modal_button.append(cuteform.find('.cuteform-selected').clone(true).off());
if (with_modal_text) {
modal_button.append('<span class="cuteform-modal-text">' + cuteform.find('.cuteform-selected').attr('data-cuteform-text') + '</span>');
} else {
modal_button.append(cuteform.find('.cuteform-selected').clone(true).off());
}
modal_button.click(function(e) {
e.preventDefault();
modal.css('display', 'block');
Expand Down
2 changes: 1 addition & 1 deletion cuteform.min.css

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

2 changes: 1 addition & 1 deletion cuteform.min.js

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

0 comments on commit d2599c8

Please sign in to comment.