#7080 Adaptation of the JS for the behavior of the aspect selection button.
This commit is contained in:
parent
29fa1e582a
commit
fa39f7d348
2 changed files with 75 additions and 1 deletions
|
|
@ -48,4 +48,78 @@ $(document).ready(function(){
|
|||
});
|
||||
|
||||
new Diaspora.MarkdownEditor("#status_message_text");
|
||||
|
||||
$(".dropdown-menu > li").bind("tap click", function(evt) {
|
||||
var target = $(evt.target).closest('li');
|
||||
|
||||
// visually toggle the aspect selection
|
||||
if (target.is('.radio')) {
|
||||
_toggleRadio(target);
|
||||
} else if (target.is('.aspect_selector')) {
|
||||
// don't close the dropdown
|
||||
evt.stopPropagation();
|
||||
_toggleCheckbox(target);
|
||||
}
|
||||
|
||||
_updateSelectedAspectIds();
|
||||
_updateButton('btn-default');
|
||||
|
||||
// update the globe or lock icon
|
||||
var icon = $("#visibility-icon");
|
||||
if (target.find(".text").text().trim() === Diaspora.I18n.t("stream.public")) {
|
||||
icon.removeClass("entypo-lock");
|
||||
icon.addClass("entypo-globe");
|
||||
} else {
|
||||
icon.removeClass("entypo-globe");
|
||||
icon.addClass("entypo-lock");
|
||||
}
|
||||
});
|
||||
|
||||
function _toggleRadio (target) {
|
||||
$('.dropdown-menu > li').removeClass('selected');
|
||||
target.toggleClass('selected');
|
||||
};
|
||||
|
||||
function _toggleCheckbox (target) {
|
||||
$('.dropdown-menu > li.radio').removeClass('selected');
|
||||
target.toggleClass('selected');
|
||||
};
|
||||
|
||||
// take care of the form fields that will indicate the selected aspects
|
||||
function _updateSelectedAspectIds() {
|
||||
var form = $("#new_status_message");
|
||||
|
||||
// remove previous selection
|
||||
form.find('input[name="aspect_ids[]"]').remove();
|
||||
|
||||
// create fields for current selection
|
||||
$('.dropdown-menu > li.selected').each(function() {
|
||||
var uid = _.uniqueId('aspect_ids_');
|
||||
var id = $(this).data('aspect_id');
|
||||
form.append(
|
||||
'<input id="'+uid+'" name="aspect_ids[]" type="hidden" value="'+id+'">'
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
// change class and text of the dropdown button
|
||||
function _updateButton(inAspectClass) {
|
||||
var button = $('.btn.dropdown-toggle'),
|
||||
selectedAspects = $(".dropdown-menu > li.selected").length,
|
||||
buttonText;
|
||||
|
||||
if (selectedAspects === 0) {
|
||||
button.removeClass(inAspectClass).addClass('btn-default');
|
||||
buttonText = Diaspora.I18n.t("aspect_dropdown.select_aspects");
|
||||
} else {
|
||||
button.removeClass('btn-default').addClass(inAspectClass);
|
||||
if (selectedAspects === 1) {
|
||||
buttonText = this.$(".dropdown-menu > li.selected .text").first().text();
|
||||
} else {
|
||||
buttonText = Diaspora.I18n.t("aspect_dropdown.toggle", { count: selectedAspects.toString() });
|
||||
}
|
||||
}
|
||||
|
||||
button.find('.text').text(buttonText);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
%i.glyphicon.glyphicon-ok
|
||||
%span.text
|
||||
= t("public")
|
||||
%li.all_aspects.radio{"data-aspect_id" => "all_aspects"}
|
||||
%li.all_aspects.radio.selected{"data-aspect_id" => "all_aspects"}
|
||||
%a
|
||||
%span.status_indicator
|
||||
%i.glyphicon.glyphicon-ok
|
||||
|
|
|
|||
Loading…
Reference in a new issue