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

Picker alt text #723

Merged
merged 2 commits into from
Jul 13, 2023
Merged
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
5 changes: 4 additions & 1 deletion handlers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PickerPopupHandler(BaseHandler):
def get(self):
url = self.get_argument('url', None)
source_url = self.get_argument('source_url', '')
alt_text = self.get_argument('alt', '')
file_name = self.get_argument('title', '')
current_user = self.get_current_user_object()

Expand Down Expand Up @@ -71,7 +72,7 @@ def get(self):
#replace plus signs with %20's
return self.render("tools/picker.html", file_name=file_name, width="", height="", \
url=parsed_url.scheme + "://" + parsed_url.netloc + parsed_url.path + parsed_url_query, \
source_url=source_url, description='', is_video=is_video, shakes=shakes,
source_url=source_url, description='', alt_text=alt_text, is_video=is_video, shakes=shakes,
can_upload_this_month=can_upload_this_month)

@tornado.web.authenticated
Expand Down Expand Up @@ -102,6 +103,7 @@ def on_response(self, response):
title = self.get_argument("title", None)
source_url = self.get_argument('source_url', None)
description = self.get_argument('description', None)
alt_text = self.get_argument('alt_text', None)
shake_id = self.get_argument('shake_id', None)

if title == file_name:
Expand Down Expand Up @@ -135,6 +137,7 @@ def on_response(self, response):
shake_id = shake_id)
sf.source_url = source_url
sf.description = description
sf.alt_text = alt_text
sf.save()
if not options.debug:
# file cleanup
Expand Down
2 changes: 1 addition & 1 deletion static/css/main.min.css

Large diffs are not rendered by default.

35 changes: 24 additions & 11 deletions static/js/tools.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/* JS for the tools page */

(function($) {

$.fn.hint = function(text) {

var default_text = text;
var field = this;
var original_color = $(this).css('color');

var setDefault = function() {
if ($(field).val() == '') {
$(field).css('color', '#999').val(default_text);
}
};

var resetStyles = function() {
$(field).css('color', original_color);
};

var clearField = function() {
$(field).val('');
};

setDefault();

this.focus(function() {
if ($(this).val() == default_text) {
resetStyles();
Expand All @@ -32,22 +32,35 @@
}).blur(function() {
setDefault();
});

// on submit, clear out the hint before submit.
this.parents('form:first').submit(function() {
if ($(field).val() == default_text) {
clearField();
}
});

return this;
};


$('.picker-content .textarea-navigation .tab').click(function(e) {
let tabId = e.target.getAttribute('data-tab');
let tab = document.getElementById(tabId);
if (tab && !$(tab).hasClass('field-textarea--selected')) {
$('.picker-content .textarea-navigation li').removeClass('selected');
$(e.target).closest('li').addClass('selected');
$('#description').removeClass('field-textarea--selected');
$('#alt-text').removeClass('field-textarea--selected');
$(tab).addClass('field-textarea--selected');
}
});


})(jQuery);


$(document).ready(function() {

$('#description-field').hint('Write a description if you\'d like!');

});
24 changes: 23 additions & 1 deletion templates/tools/picker.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ <h3>In order to post, you have to confirm your email address first. Check your e
</div>
</div>

<div class="field field-textarea">
<div class="textarea-navigation">
<ul>
<li class="selected"><span class="tab" data-tab="description">Description</a></li>
<li><span class="tab" data-tab="alt-text">Alt Text</span></li>
</ul>
</div>

<div id="description" class="field field-textarea field-textarea--selected">
<div class="field-input">
<div class="field-input-inner">
<textarea id="description-field" name="description" value="{{escape(description)}}">{% if source_url %}source: {{source_url}}{% end %}</textarea>
Expand All @@ -40,6 +47,21 @@ <h3>In order to post, you have to confirm your email address first. Check your e
</div>
</div>

<div id="alt-text" class="field field-textarea">
<div class="field-input">
<div class="field-input-inner">
<textarea id="alt-text-field" name="alt_text">{% if alt_text %}{{alt_text}}{% end %}</textarea>
{% if errors.alt_text %}
<div class="error">
<span class="error-text">
{{errors.alt_text }}
</span>
</div>
{% end %}
</div>
</div>
</div>

{% if len(shakes) > 1 %}
<div class="field tools-field-title">
<div class="field-input">
Expand Down