MCPcopy Create free account
hub / github.com/facebook/Rapid / noteSaveSection

Function noteSaveSection

modules/ui/note_editor.js:87–177  ·  view source on GitHub ↗
(selection)

Source from the content-addressed store, hash-verified

85
86
87 function noteSaveSection(selection) {
88 var isSelected = (_note && _note.id === context.selectedIDs()[0]);
89 var noteSave = selection.selectAll('.note-save')
90 .data((isSelected ? [_note] : []), function(d) { return d.status + d.id; });
91
92 // exit
93 noteSave.exit()
94 .remove();
95
96 // enter
97 var noteSaveEnter = noteSave.enter()
98 .append('div')
99 .attr('class', 'note-save save-section cf');
100
101 noteSaveEnter
102 .append('h4')
103 .attr('class', '.note-save-header')
104 .text(function() {
105 return _note.isNew() ? l10n.t('note.newDescription') : l10n.t('note.newComment');
106 });
107
108 var commentTextarea = noteSaveEnter
109 .append('textarea')
110 .attr('class', 'new-comment-input')
111 .attr('placeholder', l10n.t('note.inputPlaceholder'))
112 .attr('maxlength', 1000)
113 .property('value', function(d) { return d.newComment; })
114 .call(utilNoAuto)
115 .on('keydown.note-input', keydown)
116 .on('input.note-input', changeInput)
117 .on('blur.note-input', changeInput);
118
119 if (!commentTextarea.empty() && _newNote) {
120 // autofocus the comment field for new notes
121 commentTextarea.node().focus();
122 }
123
124 // update
125 noteSave = noteSaveEnter
126 .merge(noteSave)
127 .call(userDetails)
128 .call(noteSaveButtons);
129
130
131 // fast submit if user presses cmd+enter
132 function keydown(d3_event) {
133 if (!(d3_event.keyCode === 13 && // ↩ Return
134 d3_event.metaKey)) return;
135
136 var osm = context.services.osm;
137 if (!osm) return;
138
139 var hasAuth = osm.authenticated();
140 if (!hasAuth) return;
141
142 if (!_note.newComment) return;
143
144 d3_event.preventDefault();

Callers

nothing calls this directly

Calls 10

dataMethod · 0.80
isNewMethod · 0.80
focusMethod · 0.80
selectedIDsMethod · 0.45
removeMethod · 0.45
exitMethod · 0.45
enterMethod · 0.45
tMethod · 0.45
onMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected