Rename variable editor -> ed to avoid conflicting with the module.

Even in cases that were not causing problems, for consistency.
This commit is contained in:
voussoir 2018-07-28 15:17:18 -07:00
parent 1b90850818
commit 9c354249c9
3 changed files with 50 additions and 38 deletions

View file

@ -50,8 +50,16 @@ p
{{header.make_header(session=session)}}
<div id="content_body">
<h2>
<span data-editor-id="title" data-editor-empty-text="{{album.id}}" data-editor-placeholder="title" id="title_text">{{album.display_name}}</span>
<span
id="title_text"
data-editor-id="title"
data-editor-empty-text="{{album.id}}"
data-editor-placeholder="title"
>
{{-album.display_name-}}
</span>
</h2>
<pre
id="description_text"
data-editor-id="description"
@ -167,21 +175,21 @@ unpaste_photo_clipboard_button.innerText = "Remove from this album";
unpaste_photo_clipboard_button.onclick = unpaste_photo_clipboard;
document.getElementById("clipboard_tray_toolbox").appendChild(unpaste_photo_clipboard_button);
function on_open(editor, edit_element_map, display_element_map)
function on_open(ed, edit_element_map, display_element_map)
{
editor.open();
ed.open();
edit_element_map["title"].focus();
}
function on_save(editor, edit_element_map, display_element_map)
function on_save(ed, edit_element_map, display_element_map)
{
function callback()
{
var title_display = display_element_map["title"];
var description_display = display_element_map["description"];
editor.hide_spinner();
editor.save();
ed.hide_spinner();
ed.save();
document.title = title_display.innerText + " | Albums";
if (description_display.innerText == "")
{
@ -200,13 +208,13 @@ function on_save(editor, edit_element_map, display_element_map)
data.append("title", title_editor.value);
data.append("description", description_editor.value);
editor.show_spinner();
ed.show_spinner();
common.post(url, data, callback);
}
function on_cancel(editor, edit_element_map, display_element_map)
function on_cancel(ed, edit_element_map, display_element_map)
{
editor.cancel();
ed.cancel();
if (display_element_map["description"].innerText == "")
{
display_element_map["description"].classList.add("hidden");
@ -215,6 +223,6 @@ function on_cancel(editor, edit_element_map, display_element_map)
var title_text = document.getElementById("title_text");
var description_text = document.getElementById("description_text");
var editor = new editor.Editor([title_text, description_text], on_open, on_save, on_cancel);
var ed = new editor.Editor([title_text, description_text], on_open, on_save, on_cancel);
</script>
</html>

View file

@ -48,23 +48,27 @@
<div id="bookmarks">
{% for bookmark in bookmarks %}
<div class="bookmark_card" data-bookmark-id="{{bookmark.id}}">
<a href="{{bookmark.url}}"
<a
href="{{bookmark.url}}"
class="bookmark_title"
data-editor-id="title"
data-editor-placeholder="title (optional)"
data-editor-empty-text="{{bookmark.id}}">
{%- if bookmark.title -%}
{{bookmark.title}}
{%- else -%}
{{bookmark.id}}
{%- endif -%}
data-editor-empty-text="{{bookmark.id}}"
>
{%- if bookmark.title -%}
{{bookmark.title}}
{%- else -%}
{{bookmark.id}}
{%- endif -%}
</a>
<a href="{{bookmark.url}}"
<a
href="{{bookmark.url}}"
class="bookmark_url"
data-editor-id="url"
data-editor-placeholder="url">
{{-bookmark.url-}}
data-editor-placeholder="url"
>
{{-bookmark.url-}}
</a>
</div>
{% endfor %}
@ -104,13 +108,13 @@ function create_bookmark(url, title)
}
function on_open(editor, edit_element_map)
function on_open(ed, edit_element_map)
{
editor.open();
ed.open();
edit_element_map["title"].focus();
}
function on_save(editor, edit_element_map)
function on_save(ed, edit_element_map)
{
var title_editor = edit_element_map["title"];
var url_editor = edit_element_map["url"];
@ -120,14 +124,14 @@ function on_save(editor, edit_element_map)
return;
}
editor.show_spinner();
ed.show_spinner();
function callback()
{
editor.hide_spinner();
editor.save();
ed.hide_spinner();
ed.save();
}
var url = "/bookmark/" + editor.misc_data["bookmark_id"] + "/edit";
var url = "/bookmark/" + ed.misc_data["bookmark_id"] + "/edit";
var data = new FormData();
data.append("title", title_editor.value);
data.append("url", url_editor.value);
@ -144,8 +148,8 @@ function create_editors()
var card = cards[index];
var title_div = card.getElementsByClassName("bookmark_title")[0];
var url_div = card.getElementsByClassName("bookmark_url")[0];
editor = new editor.Editor([title_div, url_div], on_open, on_save, on_cancel);
editor.misc_data["bookmark_id"] = card.dataset.bookmarkId;
ed = new editor.Editor([title_div, url_div], on_open, on_save, on_cancel);
ed.misc_data["bookmark_id"] = card.dataset.bookmarkId;
}
}
create_editors();

View file

@ -241,24 +241,24 @@ function receive_callback(response)
}
{% if specific_tag is not none %}
function on_open(editor, edit_element_map)
function on_open(ed, edit_element_map)
{
editor.open();
ed.open();
edit_element_map["name"].focus();
}
function on_save(editor, edit_element_map, display_element_map)
function on_save(ed, edit_element_map, display_element_map)
{
var name_display = display_element_map["name"];
var name_editor = edit_element_map["name"];
var description_display = display_element_map["description"];
var description_editor = edit_element_map["description"];
editor.show_spinner();
ed.show_spinner();
function callback(response)
{
console.log(response);
editor.hide_spinner();
ed.hide_spinner();
if (response["meta"]["status"] == 200)
{
var new_name = response["data"]["name"];
@ -267,7 +267,7 @@ function on_save(editor, edit_element_map, display_element_map)
window.history.replaceState(null, null, "/tag/" + new_name);
name_editor.value = new_name;
description_editor.value = new_description;
editor.save();
ed.save();
if (new_description === "")
{
description_display.classList.add("hidden");
@ -282,9 +282,9 @@ function on_save(editor, edit_element_map, display_element_map)
common.post(url, data, callback);
}
function on_cancel(editor, edit_element_map, display_element_map)
function on_cancel(ed, edit_element_map, display_element_map)
{
editor.cancel();
ed.cancel();
if (display_element_map["description"].innerText == "")
{
display_element_map["description"].classList.add("hidden");
@ -293,7 +293,7 @@ function on_cancel(editor, edit_element_map, display_element_map)
var name_text = document.getElementById("name_text");
var description_text = document.getElementById("description_text");
var editor = new editor.Editor([name_text, description_text], on_open, on_save, on_cancel);
var ed = new editor.Editor([name_text, description_text], on_open, on_save, on_cancel);
{% endif %}
</script>
</html>